错误代码1005,SQL状态HY000:无法创建表errno:150
我正在尝试创建一个表,但是一旦我的netbeans错误DB的第一个表,脚本失败。
I'm trying to create a table but the script fails as soon as my netbeans errors the first table of DB.
如何解决这个问题?
CREATE TABLE filmy
(
Film_Id int NOT NULL,
Nazwa varchar(250),
Adres varchar(250),
Data_Utworzenia date,
Komentarz varchar(250),
Gat_Id int,
Sub_Id int,
Aut_Id int,
User_Id int,
Primary Key (Film_Id),
CONSTRAINT fk_GatFilmy FOREIGN KEY (Gat_Id) REFERENCES gatunek(Gat_Id),
CONSTRAINT fk_SubFilmy FOREIGN KEY (Sub_Id) REFERENCES subgatunek(Sub_Id),
CONSTRAINT fk_AutFilmy FOREIGN KEY (Aut_Id) REFERENCES autor(Aut_Id),
CONSTRAINT fk_UserFilmy FOREIGN KEY (User_Id) REFERENCES users(User_Id)
)
使用 show innodb status
- 埋在输出中(中间)是最后一个外键错误部分。它会解释为什么表创建失败。
Use show innodb status
- buried in the output (around the middle) is a "last foreign key error" section. It'll explain exactly why the table creation failed.
通常是由于引用FK字段不存在(错字,错误表),或有一个字段类型不匹配。 FK链接的字段必须完全匹配定义。 char(1)字段不能FK到一个char(5)字段,等...
usually it's due to a reference FK field not existing (typo, wrong table), or there's a field-type mismatch. FK-linked fields must match definitions exactly. A char(1) field can't be FK'd to a char(5) field, etc...
注意:在MySQL 5.5中, 显示引擎innodb状态
(感谢kewpiedoll99)
Note: In MySQL 5.5, the command for this is show engine innodb status
(thanks kewpiedoll99)