我试图在我的注释表中插入值,但出现错误。俗话说,我不能添加或更新子行,我也不知道这意味着什么。
我的架构看起来像这样
-- ---------------------------- -- Table structure for `comments` -- ---------------------------- DROP TABLE IF EXISTS `comments`; CREATE TABLE `comments` ( `id` varchar(36) NOT NULL, `project_id` varchar(36) NOT NULL, `user_id` varchar(36) NOT NULL, `task_id` varchar(36) NOT NULL, `data_type_id` varchar(36) NOT NULL, `data_path` varchar(255) DEFAULT NULL, `message` longtext, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_comments_users` (`user_id`), KEY `fk_comments_projects1` (`project_id`), KEY `fk_comments_data_types1` (`data_type_id`), CONSTRAINT `fk_comments_data_types1` FOREIGN KEY (`data_type_id`) REFERENCES `data_types` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_comments_projects1` FOREIGN KEY (`project_id`) REFERENCES `projects` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_comments_users` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf32; -- ---------------------------- -- Records of comments -- ---------------------------- -- ---------------------------- -- Table structure for `projects` -- ---------------------------- DROP TABLE IF EXISTS `projects`; CREATE TABLE `projects` ( `id` varchar(36) NOT NULL, `user_id` varchar(36) NOT NULL, `title` varchar(45) DEFAULT NULL, `description` longtext, `created` datetime DEFAULT NULL, `modified` datetime DEFAULT NULL, PRIMARY KEY (`id`), KEY `fk_projects_users1` (`user_id`), CONSTRAINT `fk_projects_users1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION ) ENGINE=InnoDB DEFAULT CHARSET=utf32; -- ---------------------------- -- Records of projects -- ---------------------------- INSERT INTO `projects` VALUES ('50dcbc72-3410-4596-8b71-0e80ae7aaee3', '50dcbc5c-d684-40bf-9715-0becae7aaee3', 'Brand New Project', 'This is a brand new project', '2012-12-27 15:24:02', '2012-12-27 15:24:02');
和我试图做的mysql语句看起来像这样
INSERT INTO `anthonyl_fbpj`.`comments` (`project_id`, `user_id`, `task_id`, `data_type_id`, `message`, `modified`, `created`, `id`) VALUES ('50dc845a-83e4-4db3-8705-5432ae7aaee3', '50dcbc5c-d684-40bf-9715-0becae7aaee3', '1', '50d32e5c-abdc-491a-a0ef-25d84e9f49a8', 'this is a test', '2012-12-27 19:20:46', '2012-12-27 19:20:46', '50dcf3ee-8bf4-4685-aa45-4eb4ae7aaee3')
我得到的错误看起来像这样
SQLSTATE [23000]:违反完整性约束:1452无法添加或更新子行:外键约束失败(anthonyl_fbpj。comments,CONSTRAINT fk_comments_projects1 FOREIGN KEY(project_id)引用projects(id)删除无操作,更新无操作)
anthonyl_fbpj
comments
fk_comments_projects1
project_id
projects
id
这只是意味着您要插入的project_id表上的column的值在table comments上不存在projects。请记住,列的值project_id上表comments是依赖于值ID表Projects。
ID
Projects
50dc845a-83e4-4db3-8705-5432ae7aaee3您要为column插入的值project_id在table上不存在projects。
50dc845a-83e4-4db3-8705-5432ae7aaee3