gpt4 book ai didi

mysql - 错误 1064 (42000) && 错误 1005 (HY000) : Can't create table Contact_Info_Tbl (errno: 150)

转载 作者:行者123 更新时间:2023-11-30 00:14:36 25 4
gpt4 key购买 nike

我在创建表时收到这些错误,当我取出外键时它们会起作用。我对数据库的构建相对较新,所以我可能会遗漏一些简单的东西

Create Table IF NOT EXISTS Classroom_Address_Mailing_Tbl (
ID int auto_increment primary key,
Street_Address varchar (25),
City varchar (25),
State_Abbr varchar (2),
Zipcode varchar (10)
);


Create Table IF NOT EXISTS Classroom_Address_Physical_Tbl (
ID int auto_increment primary key,
Street_Address varchar (25),
City varchar (25),
State_Abbr varchar (2),
Zipcode varchar (10)
);

Create Table IF NOT EXISTS Classroom_Info_Tbl (
ID int auto_increment primary key,
School_Name varchar (25),
Classroom_Name_Offical varchar (25),
Classroom_URL varchar (25),
Classroom_Address_Physical_ID int,
Classroom_Address_Mailing_ID int,
foreign key (Classroom_Address_Mailing_ID) references
Classroom_Address_Mailing_Tbl (ID) on delete cascade,
foreign key (Classroom_Address_Physical_ID) references
Classroom_Address_Physical_Tbl (ID) on delete cascade,
);


Create Table IF NOT EXISTS Contact_Info_Tbl (
Classroom_ID int,
Contact_Name varchar (20),
Contact_Title varchar (20),
Contact_Email varchar (20),
Contact_Phone varchar (20),
foreign key (Classroom_ID) references
Classroom_Info_Tbl (ID) on delete cascade
);

这些是我得到的错误:

错误 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 7 行“)”附近使用的正确语法

错误 1005 (HY000):无法创建表“neClassCertForm.Contact_Info_Tbl”(错误号:150)

最佳答案

好吧,问题是创建表中的逗号

Classroom_Address_Physical_Tbl (ID) on delete cascade,

这破坏了表的创建。还要添加 ENGINE=innodb 以强制执行外键约束。

Create Table IF NOT EXISTS `Classroom_Address_Mailing_Tbl` (
ID int auto_increment primary key,
Street_Address varchar (25),
City varchar (25),
State_Abbr varchar (2),
Zipcode varchar (10)
)ENGINE=InnoDB;


Create Table IF NOT EXISTS `Classroom_Address_Physical_Tbl` (
ID int auto_increment primary key,
Street_Address varchar (25),
City varchar (25),
State_Abbr varchar (2),
Zipcode varchar (10)
)ENGINE=InnoDB;

Create Table IF NOT EXISTS `Classroom_Info_Tbl` (
ID int auto_increment primary key,
School_Name varchar (25),
Classroom_Name_Offical varchar (25),
Classroom_URL varchar (25),
Classroom_Address_Physical_ID int,
Classroom_Address_Mailing_ID int,
foreign key (Classroom_Address_Mailing_ID) references
Classroom_Address_Mailing_Tbl (ID) on delete cascade,
foreign key (Classroom_Address_Physical_ID) references
Classroom_Address_Physical_Tbl (ID) on delete cascade
)ENGINE=InnoDB;


Create Table IF NOT EXISTS `Contact_Info_Tbl` (
Classroom_ID int,
Contact_Name varchar (20),
Contact_Title varchar (20),
Contact_Email varchar (20),
Contact_Phone varchar (20),
index ci (Classroom_ID),
foreign key (Classroom_ID) references
Classroom_Info_Tbl (ID) on delete cascade
)ENGINE=InnoDB;

关于mysql - 错误 1064 (42000) && 错误 1005 (HY000) : Can't create table Contact_Info_Tbl (errno: 150),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23765250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com