使用外键的SQL时出错

时间:2021-04-06 21:53:55
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)
);

This is my SQL query. I am getting this error

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

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

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

1 个解决方案

#1


0  

Actually sorry for the inconvenience but I am very new to mysql, so I would like to share how I solved it. This query is absolutely right, My sql Foreign key used for connecting two tables. This helps making interface and it is also very safe. I was getting that error because of wrong table name. Suppose if you have given the reference- FOREIGN KEY (user_one) REFERENCES users(user_id), then 'user' is table name and user_id is row that exist in it. So it was my fault I am sorry for wrong question.

其实很抱歉给我带来不便,但我对mysql很新,所以我想分享一下我是如何解决它的。这个查询是绝对正确的,我的sql外键用于连接两个表。这有助于制作界面,也非常安全。由于表名错误,我收到了这个错误。假设您已经提供了引用FOREIGN KEY(user_one)REFERENCES用户(user_id),那么'user'是表名,user_id是其中存在的行。所以这是我的错,我为错误的问题感到抱歉。

#1


0  

Actually sorry for the inconvenience but I am very new to mysql, so I would like to share how I solved it. This query is absolutely right, My sql Foreign key used for connecting two tables. This helps making interface and it is also very safe. I was getting that error because of wrong table name. Suppose if you have given the reference- FOREIGN KEY (user_one) REFERENCES users(user_id), then 'user' is table name and user_id is row that exist in it. So it was my fault I am sorry for wrong question.

其实很抱歉给我带来不便,但我对mysql很新,所以我想分享一下我是如何解决它的。这个查询是绝对正确的,我的sql外键用于连接两个表。这有助于制作界面,也非常安全。由于表名错误,我收到了这个错误。假设您已经提供了引用FOREIGN KEY(user_one)REFERENCES用户(user_id),那么'user'是表名,user_id是其中存在的行。所以这是我的错,我为错误的问题感到抱歉。