[英]#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 isNOT NULL
- you don't have to specify adefault value
if it has the specialauto_increment
option when youcreate
thetable
.尽管
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 )
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.