【发布时间】:2018-09-18 11:13:26
【问题描述】:
我在导入旧的 SQL 文件并全部修复时不断出错,但我卡住了,无法理解这意味着什么。
改变表
property添加约束property_ibfk_1外键 (intid) 参考interiors(id) 更新时删除级联 级联,添加约束property_ibfk_2外键 (owner) 参考accounts(id) 更新级联时删除设置空 MySQL 说:文档1452 - 无法添加或更新子行:外键约束失败(
ionicnew.#sql-252c_e1, CONSTRAINTproperty_ibfk_2FOREIGN 键 (owner) 引用accounts(id) 开 删除 设置 NULL 开 更新级联)
property表的完整代码:
CREATE TABLE `property` (
`id` int(11) NOT NULL,
`x` float NOT NULL,
`y` float NOT NULL,
`z` float NOT NULL,
`a` float NOT NULL,
`type` bit(32) NOT NULL,
`intid` int(11) NOT NULL,
`name` varchar(128) NOT NULL,
`price` int(11) NOT NULL,
`mapicon` tinyint(3) UNSIGNED NOT NULL,
`status` tinyint(3) UNSIGNED NOT NULL,
`point` int(10) UNSIGNED NOT NULL,
`saleprice` int(11) NOT NULL DEFAULT '0',
`owner` int(11) DEFAULT NULL,
`money` int(11) NOT NULL DEFAULT '0',
`level` tinyint(3) UNSIGNED NOT NULL DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `property`
ADD PRIMARY KEY (`id`),
ADD KEY `intid` (`intid`),
ADD KEY `owner` (`owner`);
ALTER TABLE `property`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=86;
ALTER TABLE `property`
ADD CONSTRAINT `property_ibfk_1` FOREIGN KEY (`intid`) REFERENCES `interiors` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `property_ibfk_2` FOREIGN KEY (`owner`) REFERENCES `accounts` (`id`) ON DELETE SET NULL ON UPDATE CASCADE;
如果需要,我可以上传完整的 SQL 文件。
【问题讨论】:
-
可以为
interiors和accounts添加表格描述 -
我们需要查看
property和另外两个引用表interiors和accounts中的数据。