无法创建表(错误号:150)?

时间:2011-11-12 17:36:57

标签: mysql sql

我在MACOSX上使用sequel pro并且我已经定义了包含外键的表,它仍然给我这个错误无法创建表(错误号: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 个答案:

答案 0 :(得分:5)

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

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)


)

答案 1 :(得分:1)

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

FOREIGN KEY (mem_id) REFERENCES members(mem_id)