How to alter a MySQL table's foreign key using the command line

前端 未结 4 2067
一整个雨季
一整个雨季 2021-02-13 19:49

How to alter an existing table in MySQL, setting foreign key to another table, using the command line?

4条回答
  •  故里飘歌
    2021-02-13 20:07

    If you have multiple foreign keys chained together and you get an error that ends with errorno 15x it most likely means that there are other tables that are dependent on the foreign key that you're trying to drop.

    To drop the foreign key when you get that error, you will need to do SET FOREIGN_KEY_CHECKS = 0; and then you must first drop the foreign keys on the tables that don't have any other tables dependent on them. You can then successfully drop the foreign keys on the next table up in the chain and so on.

    When you're done, make sure you run SET FOREIGN_KEY_CHECKS = 1; again.

提交回复
热议问题