# 1067 - Invalid default value for 'bonusid', how can I fix this error?

SQL query:

CREATE TABLE bonus(
bonusid INT( 10 ) DEFAULT  '0' NOT NULL AUTO_INCREMENT ,
empid INT( 10 ) DEFAULT  '0' NOT NULL ,
datebonus DATE DEFAULT  '0000-00-00' NOT NULL ,
bonuspayment VARCHAR( 200 ) NOT NULL ,
note TEXT NOT NULL ,
PRIMARY KEY ( bonusid )
);

      

MySQL said: Documentation

1067 - Invalid default value for 'bonusid'

+3


source to share


3 answers


You don't need to provide a default value for the auto-incremented primary key. Since you have defined bonusid

as primary key and defined autoincrement. This way, a new value will be automatically created for bonusid

whenever a new record is inserted. Try for example this



CREATE TABLE bonus(
   bonusid INT( 10 ) NOT NULL AUTO_INCREMENT ,
   empid INT( 10 ) DEFAULT  '0' NOT NULL ,
   datebonus DATE DEFAULT  '0000-00-00' NOT NULL ,
   bonuspayment VARCHAR( 200 ) NOT NULL ,
   note TEXT NOT NULL ,
   PRIMARY KEY ( bonusid )
);

      

+3


source


the default is not allowed to the primary key due to the fact that you used the default for the primary key and then for a while when the record was inserted as such and the primary key is not allowed to insert the same value into that column.

check it

CREATE TABLE bonus(
bonusid INT( 10 )  AUTO_INCREMENT ,
empid INT( 10 ) DEFAULT  '0' NOT NULL ,
datebonus DATE DEFAULT  '0000-00-00' NOT NULL ,
bonuspayment VARCHAR( 200 ) NOT NULL ,
note TEXT NOT NULL ,
PRIMARY KEY ( bonusid )
);

      



if you are using any column as primary key then by default null is not used to declare this. refer to this link for auto increment

http://www.w3schools.com/sql/sql_autoincrement.asp

+1


source


Even if the column is - you don't need to specify if it has a special option when you . bonusid

NOT NULL

default value

auto_increment

create

table

Try:

CREATE TABLE bonus(
bonusid INT( 10 ) NOT NULL AUTO_INCREMENT ,
empid INT( 10 ) DEFAULT  '0' NOT NULL ,
datebonus DATE DEFAULT  '0000-00-00' NOT NULL ,
bonuspayment VARCHAR( 200 ) NOT NULL ,
note TEXT NOT NULL ,
PRIMARY KEY ( bonusid )
);

      

FIDDLE DEMO HERE

0


source







All Articles