我有:
CREATE TABLE place(
placeid int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
placename varchar(255),
placeinfo text,
locationx double,
locationy double
);
并创建TABLE位置没问题,但后来我创建了:
CREATE TABLE city(
cityid int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
placeid int,
cityname varchar(255),
image text,
constraint n foreign key(placeid) references place(placeid)
);
我收到错误:
Can't create table `travel`.`city` (errno: 150 "Foreign key constraint is incorrectly formed")
如何解决?
答案 0 :(得分:0)
CITY表中的placeid列不是UNSIGNED INT,因为它在PLACE表中。
CREATE TABLE city(
cityid int UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
placeid int UNSIGNED,
cityname varchar(255),
image text,
constraint n foreign key(placeid) references place(placeid)
)