mysql> describe location;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| locX | float | NO | | NULL | |
| locY | float | NO | | NULL | |
| name | varchar(90) | NO | | NULL | |
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
+-------+------------------+------+-----+---------+----------------+
4 rows in set (0.01 sec)
mysql> create table user(
id INT,
locationID INT,
ageRange varChar(10) NOT NULL,
gender enum('y', 'n') NOT NULL,
safeSleep enum('y', 'n') NOT NULL,
famViol enum('y', 'n') NOT NULL,
traveller enum('y', 'n') NOT NULL,
family enum('y', 'n') NOT NULL,
couples enum('y', 'n') NOT NULL,
mentEmot enum('y', 'n') NOT NULL,
parole enum('y', 'n') NOT NULL,
disabled enum('y', 'n') NOT NULL,
veteran enum('y', 'n') NOT NULL,
asylum enum('y', 'n') NOT NULL,
pets enum('y', 'n') NOT NULL,
INDEX par_ind (locationID),
CONSTRAINT fk_locat FOREIGN KEY (locationID)
REFERENCES location(id)
ON DELETE CASCADE
ON UPDATE CASCADE
) ENGINE=INNODB;
我尝试创建外键的表格显示在顶部。为什么我收到错误消息?我之前使用过相同的方法制作外键,但是这个方法使用相同的代码不起作用。我正在自学SQL,所以没有很多经验。谢谢