SOLVED : Drop table fails

Post Reply
mister_v
Posts: 180
Joined: Thu Mar 04, 2010 9:19 pm

SOLVED : Drop table fails

Post 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 |
Last edited by mister_v on Mon Feb 05, 2018 12:14 pm, edited 1 time in total.
chris
Site Admin
Posts: 182
Joined: Mon Jul 21, 2008 9:52 am

Re: Drop table fails

Post 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.
mister_v
Posts: 180
Joined: Thu Mar 04, 2010 9:19 pm

Re: Drop table fails

Post by mister_v »

Thanks, forgot that one.
Post Reply