简体   繁体   English

#1067 - 'bonusid'的默认值无效如何修复此错误?

[英]#1067 - Invalid default value for 'bonusid' how can i fix this error?

SQL query: SQL查询:

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 MySQL说:文档

1067 - Invalid default value for 'bonusid' 1067 - 'bonusid'的默认值无效

You don't have to give default value for a primary key with auto increment value. 您不必为具有自动增量值的主键提供默认值。 Since you have defined bonusid as a primary key and has defined auto increment.So this will automatically create a new value for bonusid whenever a new record is inserted.So try like this 由于您已将bonusid定义为主键并已定义自动增量。 bonusid每当插入新记录时,这将自动为bonusid创建一个新值。 bonusid尝试这样

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 )
);

default value is not allowed to the primary key because of if you used default value to primary key then some time the record is inserted as same and primary key is not allowed to insert same value in this column. 默认值不允许使用主键,因为如果您使用默认值到主键,则某些时候将记录插入为相同,并且不允许主键在此列中插入相同的值。

check this 检查一下

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 use some column as primary key then it is default not null is not use to declare this. 如果您使用某个列作为主键,那么它默认不为null不用于声明它。 refer this link for auto increment 请参阅此链接以获取自动增量

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

Even though the bonusid column is NOT NULL - you don't have to specify a default value if it has the special auto_increment option when you create the table . 尽管bonusid列是NOT NULL - 如果在create table时它具有特殊的auto_increment选项,则不必指定default value

Try As follows: 尝试如下:

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 FIDDLE DEMO在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM