Mysql create table with multiple foreign key on delete set null

后端 未结 4 1826
粉色の甜心
粉色の甜心 2021-01-12 05:59

I am trying to create a database with multiple foreign keys with delete/ update constraints, but I got a error code 1005 with following sql scripts:

CREATE T         


        
4条回答
  •  萌比男神i
    2021-01-12 06:18

    Try with create table(innoDB enginer) without foreign key and use the update table with constraint syntax, for example:

    ALTER TABLE `vineyard`
            ADD CONSTRAINT `relation_farmer_has_many_vineyards`
                FOREIGN KEY (`farmer_id`)
                REFERENCES `worker` (`worker_id`)
                ON DELETE SET NULL
                ON UPDATE CASCADE;
    

    Reference:

    • http://dev.mysql.com/doc/refman/5.6/en/innodb-foreign-key-constraints.html

    Trick: is not recommended to use capital letters(or camel case) in the names of the tables that the behavior differs from the operating system being used:

    • http://dev.mysql.com/doc/refman/5.1/en/identifier-case-sensitivity.html

提交回复
热议问题