"mysql: all parts of primary key must be not null; if you need null in a key, use unique instead" Code Answer

2

as of mysql 5.7, it no longer supports null values for the primary key.

see the documentation here:

a unique index where all key columns must be defined as not null. if they are not explicitly declared as not null, mysql declares them so implicitly (and silently). a table can have only one primary key.

so, your user_id key cannot be null if it's going to be used as a primary key. you should declare it as non-nullable:

create table `bucketlist`.`tbl_user` (
  `user_id` bigint auto_increment,
  `user_name` varchar(45) null,
  `user_username` varchar(45) null,
  `user_password` varchar(45) null,
primary key (`user_id`));

(notice the lack of null after bigint)

By Samson Wong on May 20 2022

Answers related to “mysql: all parts of primary key must be not null; if you need null in a key, use unique instead”

Only authorized users can answer the Search term. Please sign in first, or register a free account.