【问题标题】:Getting an error while SQL with Foreign KEY使用外键执行 SQL 时出错
【发布时间】:2016-05-08 00:04:15
【问题描述】:
CREATE TABLE IF Not EXISTS  `conversation` (
`c_id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
`user_one` int(11) NOT NULL,
`user_two` int(11) NOT NULL,
`ip` varchar(30) DEFAULT NULL,
`time` int(11) DEFAULT NULL,
 FOREIGN KEY (user_one) REFERENCES users(user_id),
 FOREIGN KEY (user_two) REFERENCES users(user_id)
);

这是我的 SQL 查询。我收到此错误

1215 - Impossible d'ajouter des contraintes d'index externe

【问题讨论】:

标签: mysql


【解决方案1】:

真的很抱歉给您带来不便,但我对mysql很陌生,所以我想分享一下我是如何解决它的。这个查询是绝对正确的,My sql Foreign key 用于连接两个表。这有助于制作界面,也非常安全。由于错误的表名,我收到了该错误。假设如果您已经给出了引用- FOREIGN KEY (user_one) REFERENCES users(user_id),那么“user”是表名,user_id 是其中存在的行。所以这是我的错,我很抱歉问错了问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多