Mysql create table with multiple foreign key on delete set null(Mysql在删除集null时创建具有多个外键的表)
问题描述
我正在尝试使用具有删除/更新约束的多个外键创建一个数据库,但我收到了错误代码 1005,其中包含以下 sql 脚本:
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:
错误代码说创建 Vineyard 表失败,我只想知道使用删除/更新控制创建多个外键的正确格式.
The error code says that fail to create the Vineyard table, I just want to know the proper format for creating multiple foreign keys with delete/update control.
推荐答案
你的外键规则是 ON DELETE SET NULL
但你的列定义是 NOT NULL
.
Your foreign key rule is ON DELETE SET NULL
but your column definition is NOT NULL
.
要么更改列定义并删除 NOT NULL
部分,要么过度考虑外键规则.这行得通:
Either change your column definition and remove the NOT NULL
part or overthink your foreign key rule. That works:
SQLFiddle 演示
这篇关于Mysql在删除集null时创建具有多个外键的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!