DROP all foreign keys in MYSQL database

前端 未结 4 1545
被撕碎了的回忆
被撕碎了的回忆 2020-12-24 01:33

Foreign keys are causing me too many problems modifying an database structure to meet new requirements - I want to modify primary keys but it seems I can\'t when foreign key

4条回答
  •  悲&欢浪女
    2020-12-24 02:20

    You can simply issue the following command before any Alter Table statements you are going to make:

    SET foreign_key_checks = 0;
    

    This will turn off foreign key constraint checks for your database connection. You can then make your changes without needing to worry about constraints.

    After you are done, don't forget to issue:

    SET foreign_key_checks = 1;
    

    To turn them back on.

    Note that this will still not allow you to create a new foreign key constraint that would fail because the column data types don't match.

提交回复
热议问题