mysql> DESCRIBE questions;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(255) | NO | PRI | NULL | auto_increment |
| question | varchar(255) | NO | | NULL | |
| type | char(1) | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
mysql> DESCRIBE answers;
+--------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------------+--------------+------+-----+---------+----------------+
| id | int(255) | NO | PRI | NULL | auto_increment |
| answer | varchar(255) | NO | | NULL | |
| questionid | int(255) | NO | | NULL | |
| questions_id | int(255) | NO | | NULL | |
+--------------+--------------+------+-----+---------+----------------+
I am using this statement:
ALTER TABLE answers ADD FOREIGN KEY(questions_id) REFERENCES questions(id);
but i get this error:
ERROR 1452 (23000): Cannot add or update a child row: a foreign key constraint fails (
surveydb
.#sql-df_32
, CONSTRAINT#sql-df_32_ibfk_1
FOREIGN KEY (questions_id
) REFERENCESquestions
(id
))to your MySQL server version for the right syntax to use near 'DESCREBE questions' at line 1