B
B
BonBon Slick2020-09-17 13:06:37
MySQL
BonBon Slick, 2020-09-17 13:06:37

ERROR 1215 (HY000): Cannot add foreign key constraint?

https://dev.mysql.com/doc/refman/5.6/en/create-tab...

mysql> ALTER TABLE user_notification_settings ADD CONSTRAINT FK_7051D51E4FBDA576 FOREIGN KEY (eid) REFERENCES events (id);

ERROR 1215 (HY000): Cannot add foreign key constraint

mysql> desc user_notification_settings;                                         +--------------+--------------+------+-----+---------+----------------+
| Field        | Type         | Null | Key | Default | Extra          |
+--------------+--------------+------+-----+---------+----------------+
| id           | int(11)      | NO   | PRI | NULL    | auto_increment |
| uid          | int(11)      | YES  | MUL | NULL    |                |
| eid          | int(11)      | YES  |     | NULL    |                |
| key          | varchar(255) | YES  |     | NULL    |                |
| app          | int(11)      | YES  |     | NULL    |                |
| email        | int(11)      | YES  |     | NULL    |                |
| sms          | int(11)      | YES  |     | NULL    |                |
| last_changed | timestamp    | YES  |     | NULL    |                |
+--------------+--------------+------+-----+---------+----------------+
8 rows in set (0.00 sec)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lazy @BojackHorseman MySQL, 2020-09-17
Tag

1. data inconsistency.
2. type inconsistency.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question