How to remove constraints from my MySQL table?

前端 未结 12 1455
北恋
北恋 2020-11-30 18:03

I want to remove constraints from my table. My query is:

ALTER TABLE `tbl_magazine_issue` 
DROP CONSTRAINT `FK_tbl_magazine_issue_mst_users`
<
12条回答
  •  一生所求
    2020-11-30 19:01

    Some ORM's or frameworks use a different naming convention for foreign keys than the default FK_[parent table]_[referenced table]_[referencing field], because they can be altered.

    Laravel for example uses [parent table]_[referencing field]_foreign as naming convention. You can show the names of the foreign keys by using this query, as shown here:

    SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE 
    WHERE REFERENCED_TABLE_SCHEMA = '' AND REFERENCED_TABLE_NAME = '';
    

    Then remove the foreign key by running the before mentioned DROP FOREIGN KEY query and its proper name.

    提交回复
    热议问题