How can I add ON DELETE constraint on the table?

后端 未结 2 1448
终归单人心
终归单人心 2021-02-01 14:30

How can I add ON DELETE constraint on the table?

2条回答
  •  旧巷少年郎
    2021-02-01 14:34

    If the foreign key is already created, there is a trick that worked for me. You can modified the dump of your database and import it again with the modifications.

    If you are using Mysql and Linux shell, it'd be like this:

    First, export your database:

    $ mysql -u  -p  > database.sql
    

    Then, open the database.sql file and look for the table you want to alter.

    Add ON DELETE CASCADE at the end of the foreign key sentence and save it.

    Second, import your database with the modifications:

    $ mysql -u  -p  < database.sql
    

    And you will have your ON DELETE CASCADE working.

提交回复
热议问题