错误1005(HY000):无法创建表'project.Event'(错误号:150)* mySQL *创建表错误

时间:2022-09-19 20:39:18

The following is a code snippet for a create table script that my team is using for a project. The script works on our server, but fails with the error 150 on my local machine, it is driving me mad.

以下是我的团队用于项目的create table脚本的代码片段。该脚本在我们的服务器上运行,但在本地计算机上出现错误150失败,这让我很生气。

(the script is a lot longer and includes drop table for all tables at the beginning)

(脚本更长,包括开头所有表的drop table)

/* Create Type table */
CREATE TABLE Types
    (typeID TINYINT not null,
     typeName VARCHAR (7) not null,
     PRIMARY KEY (typeID));

/* Create Event table */
CREATE TABLE Event
    (title VARCHAR (25) not null,
     typeID TINYINT not null,
     description VARCHAR (100),
     PRIMARY KEY (title),
     FOREIGN KEY (typeID) REFERENCES Types);

I've attempted to fix this through searching but every result I've come across says to check data-type, etc. The code looks good to me so I can't for the life of me figure it out. Any set of eyes to peak would be appreciated.

我试图通过搜索来解决这个问题,但我遇到的每一个结果都说检查数据类型等等。代码对我来说很好,所以我不能为我的生活弄清楚。任何一组高峰的眼睛都会受到赞赏。

Thanks!

1 个解决方案

#1


0  

You need to inform references which field of the table while defining the foreign key

您需要在定义外键时通知引用表的哪个字段

FOREIGN KEY (typeID) REFERENCES Types(typeID));

FOREIGN KEY(typeID)REFERENCES类型(typeID));

#1


0  

You need to inform references which field of the table while defining the foreign key

您需要在定义外键时通知引用表的哪个字段

FOREIGN KEY (typeID) REFERENCES Types(typeID));

FOREIGN KEY(typeID)REFERENCES类型(typeID));