错误代码1005,SQL状态HY000:无法创建表errno:150 [英] Error code 1005, SQL state HY000: Can't create table errno: 150

查看:440
本文介绍了错误代码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)

这篇关于错误代码1005,SQL状态HY000:无法创建表errno:150的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆