Page 1 of 1

SOLVED : Drop table fails

Posted: Tue Jan 30, 2018 7:51 pm
by mister_v
Hello,

I can't drop a table,
It complains about a foreign key:

Code: Select all

DROP TABLE color;
ERROR 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
But the are no constraints on the table:

Code: Select all

SHOW CREATE TABLE color
    -> ;
+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table       | Create Table                                                                                                                                                                                                                    |
+-------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| fiber_color | CREATE TABLE `color` (
  `id` int(11) NOT NULL,
  `name_en` varchar(25) NOT NULL,
  `name_nl` varchar(25) DEFAULT NULL,
  `name_fr` varchar(25) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 |

Re: Drop table fails

Posted: Tue Jan 30, 2018 8:44 pm
by chris
The foreign key is actually on another table;
Use this command to find it:

Code: Select all

SELECT * FROM information_schema.table_constraints WHERE constraint_schema = 'DATABASE_NAME' AND constraint_type = 'FOREIGN KEY' ;
Once you find it, you can remove it on that table:

Code: Select all

ALTER TABLE other_table DROP FOREIGN KEY constraint_name;
Than you should be able to drop the table.

Re: Drop table fails

Posted: Mon Feb 05, 2018 12:14 pm
by mister_v
Thanks, forgot that one.