mysql建表是报错1005 具体错误原因如下
15031316:04:06Errorinforeignkeyconstraintoftablemysql/userbase:foreignkey(UserCode)re...
150313 16:04:06 Error in foreign key constraint of table mysql/userbase:
foreign key(UserCode)references UserSalary(UserCode)):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
建表语句如下:
第一个表:
create table UserSalary(
UserId int not null primary key auto_increment,
UserCode Varchar(6) not null,
NumSalary Double(9,2) not null,
Mon int not null);
第二个表:
create table userbase(
UserCode Varchar(6) not null,
UserName Varchar(20) not null,
UserSex Varchar(3),
UserBirday Date,
primary key(UserCode),
foreign key(UserCode)references UserSalary(UserCode));
建第二个表是因为有了主外键关系 ,提示1005错误 展开
foreign key(UserCode)references UserSalary(UserCode)):
Cannot find an index in the referenced table where the
referenced columns appear as the first columns, or column types
in the table and the referenced table do not match for constraint.
Note that the internal storage type of ENUM and SET changed in
tables created with >= InnoDB-4.1.12, and such columns in old tables
cannot be referenced by such columns in new tables.
See http://dev.mysql.com/doc/refman/5.5/en/innodb-foreign-key-constraints.html
for correct foreign key definition.
建表语句如下:
第一个表:
create table UserSalary(
UserId int not null primary key auto_increment,
UserCode Varchar(6) not null,
NumSalary Double(9,2) not null,
Mon int not null);
第二个表:
create table userbase(
UserCode Varchar(6) not null,
UserName Varchar(20) not null,
UserSex Varchar(3),
UserBirday Date,
primary key(UserCode),
foreign key(UserCode)references UserSalary(UserCode));
建第二个表是因为有了主外键关系 ,提示1005错误 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询