![]() This is because the MyISAM engine doesn’t support adding foreign key constraints, so when you try to add a foreign key constraint to the table, it will trigger the ERROR 1215. I am currently working through my MySQL task and have come across a small hiccup whilst using foreign keys. ![]() To solve this you have to truncate table 1 and set the auto increment value back to 1. You need to check whether the existing table and the table you want to create are using InnoDB engine. If you have inserted a row into table 1 before creating the foreign key in table 2, then you will get a foreign key constraint error, because the auto increment value is 2 in table 1 and 1 in table 2. Part of the reloading process involved changing a data type for one of the fields, which made the foreign key from the other table invalid, thus triggering error 1215. Efectivamente, como te recomienda AgustinG, creando un índice en clientes. Make sure your tables are using InnoDB engine The problem was there was another table in the database that had a foreign key to the table I had deleted and was reloading. Once you are sure you have the correct syntax, let’s check the engine used by your tables next. Once you have the correct syntax, make sure that there’s no typo in, , and or you may trigger the same error. You can use following code: drop table Doctor CREATE TABLE Doctor ( StaffNumber INT (9) NOT NULL, INDEX (StaffNumber. In doctor it is varchar and in employee it is int. mysql> SHOW TABLES LIKE 'par' Empty set (0.00 sec) We go ahead and create the. Please add unique key in EmployeeContactNumber in Employee table and then data type of StaffType is not same in both doctor and employee table. You must replace next to the FOREIGN KEY syntax with the column name in the current table, while and must refer to the table and column name of an existing table. mysql> CREATE TABLE child ( -> id INT(10) NOT NULL PRIMARY KEY, -> parentid INT(10), -> FOREIGN KEY (parentid) REFERENCES parent(id) -> ) ENGINE INNODB ERROR 1215 (HY000): Cannot add foreign key constraint We check for the parent table and is not there.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |