Why does an error occur if I delete the foreign key from the beginning from the child, and then the primary from the parent table?

ALTER TABLE `docher` DROP FOREIGN KEY `id`; ALTER TABLE rodit DROP primary key; 

Closed due to the fact that it was off-topic by the participants default locale , Yaant , Suvitruf , mkkik , entithat May 28 at 7:15 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - default locale, Yaant, Suvitruf, mkkik, entithat
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Most likely due to the fact that there is still a connection. - KiTE
  • Could you add the output of the show create table rodit and show create table docher commands to the question? - alexlz
  • And the text of the error would not hurt - KiTE
  • And if on the contrary - then everything is fine? - Chad
  • not . . . - Ksenia

1 answer 1

A foreign key can usually only be deleted if it is not used, i.e. if there are no records to which it refers. If you want to nail the key, without losing the data, then you need to duplicate the column first, then transfer the data from the key column to it, then reset the keys, and then nail the foreign key. Something like this.