Menu

Error #1171 - All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

Help
2017-12-28
2022-11-23
  • Javier Polo Cózar

    Hello,
    When I try to import sql file into addressbook mysql database with:

    mysql -u root -p -Daddressbook <addressbook.sql
    

    It returns:

    ERROR 1171 (42000) at line 12: All parts of a PRIMARY KEY must be NOT NULL; if you nee                                    d NULL in a key, use UNIQUE instead
    

    It happens same if I do it via phpmyadmin

    It means that deprecated field is part of PRIMARY KEY as it says here:

    PRIMARY KEY (id,deprecated,domain_id),
    

    But can't be default as it's defined here:

    deprecated datetime default NULL,
    

    So please, fix addressbook.sql file so we can import and try your app.

    I guess there are other problem in definition of tables, just look at first table, addressbook!.
    Thanks you in advance!

    My data:
    OS: Ubuntu Server 16.04
    Mysql: 5.7.20
    Php: 5.6, 7.0 y 7.1

     
  • Craig Arno

    Craig Arno - 2018-06-07

    Addressbook v9.0.0.1

    root# php -v
    PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS )
    Copyright (c) 1997-2017 The PHP Group
    Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.30-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
    root# mysql -V
    mysql Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using EditLine wrapper

    I edited config/cfg.db.php to point to my local database with correct user/password information [page 2 of User Guide]

    root# mysql -u addressbook -psecret -Daddressbook <addressbook.sql
    mysql: [Warning] Using a password on the command line interface can be insecure.
    ERROR 1171 (42000) at line 12: All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead

    phpMyAdmin 4.8.1 gave the same result using Import...

    Line 12 of addressbook.sql is:

    CREATE TABLE addressbook (
    domain_id int(9) unsigned NOT NULL default 0,
    id int(9) unsigned NOT NULL,
    firstname varchar(255) NOT NULL,
    middlename varchar(255) NOT NULL,
    lastname varchar(255) NOT NULL,
    nickname varchar(255) NOT NULL,
    company varchar(255) NOT NULL,
    title varchar(255) NOT NULL,
    address text NOT NULL,
    addr_long text,
    addr_lat text,
    addr_status text,
    home text NOT NULL,
    mobile text NOT NULL,
    work text NOT NULL,
    fax text NOT NULL,
    email text NOT NULL,
    email2 text NOT NULL,
    email3 text NOT NULL,
    im text NOT NULL,
    im2 text NOT NULL,
    im3 text NOT NULL,
    homepage text NOT NULL,
    bday tinyint(2) NOT NULL,
    bmonth varchar(50) NOT NULL,
    byear varchar(4) NOT NULL,
    aday tinyint(2) NOT NULL,
    amonth varchar(50) NOT NULL,
    ayear varchar(4) NOT NULL,
    address2 text NOT NULL,
    phone2 text NOT NULL,
    notes text NOT NULL,
    photo mediumtext,
    x_vcard mediumtext,
    x_activesync mediumtext,
    created datetime default NULL,
    modified datetime default NULL,
    deprecated datetime default NULL,
    password varchar(256) default NULL,
    login date default NULL,
    role varchar(256) default NULL,
    PRIMARY KEY (id,deprecated,domain_id),
    KEY deprecated_domain_id_idx (deprecated,domain_id)
    ) DEFAULT CHARSET=utf8;

     

    Last edit: Craig Arno 2018-06-07
  • Justin Pfeil

    Justin Pfeil - 2018-07-03

    Did you giys figure this one out?

     
  • Alton

    Alton - 2022-11-23

    I replaced all the 'deprecated datetime default NULL' occurencies with 'deprecated datetime default '2001-01-01'', it did work as an intermittent solution for me

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.