无法创建表(errno: 150)?

时间:2022-06-06 20:44:10

i am using sequel pro on MACOSX and i've defined the table containing the foreign key and it still gives me this error Can't create table (errno: 150)

我在MACOSX上使用sequel pro,我定义了包含外键的表,它仍然给我这个错误不能创建表(errno: 150)

CREATE TABLE members (
mem_id INTEGER,
f_name VARCHAR(10),
l_name VARCHAR(10),
address VARCHAR(40),
name VARCHAR(20),
domain VARCHAR(15),
PRIMARY KEY(mem_id)
)

CREATE TABLE member_phone (
mem_id INTEGER,
phone_no INTEGER,
PRIMARY KEY (mem_id,phone_no),
FOREIGN KEY (mem_id) REFERENCES members
)

2 个解决方案

#1


5  

You need to specify which reference column is the target:

您需要指定哪个参考列是目标:

CREATE TABLE members (
mem_id INTEGER,
f_name VARCHAR(10),
l_name VARCHAR(10),
address VARCHAR(40),
name VARCHAR(20),
domain VARCHAR(15),
PRIMARY KEY(mem_id)
)

CREATE TABLE member_phone (
mem_id INTEGER,
phone_no INTEGER,
PRIMARY KEY (mem_id,phone_no),
FOREIGN KEY (mem_id) REFERENCES members (mem_id)


)

#2


1  

Your foreign key in member_phone needs to reference the column within the members table:

member_phone中的外键需要引用成员表中的列:

FOREIGN KEY (mem_id) REFERENCES members(mem_id)

#1


5  

You need to specify which reference column is the target:

您需要指定哪个参考列是目标:

CREATE TABLE members (
mem_id INTEGER,
f_name VARCHAR(10),
l_name VARCHAR(10),
address VARCHAR(40),
name VARCHAR(20),
domain VARCHAR(15),
PRIMARY KEY(mem_id)
)

CREATE TABLE member_phone (
mem_id INTEGER,
phone_no INTEGER,
PRIMARY KEY (mem_id,phone_no),
FOREIGN KEY (mem_id) REFERENCES members (mem_id)


)

#2


1  

Your foreign key in member_phone needs to reference the column within the members table:

member_phone中的外键需要引用成员表中的列:

FOREIGN KEY (mem_id) REFERENCES members(mem_id)