作者:Melody-Zhu1988 | 来源:互联网 | 2023-07-29 15:43
IvebeenhintedintogivingforeignkeysagoasImtryingtogetbetteratdatabaseprogramming.
I've been hinted into giving foreign keys a go as I'm trying to get better at database programming. The problem was, if a job in the jobs table was deleted, it left orphan messages relating to it in the messages table. So foreign keys were introduced to me to be the solution.
我一直暗示要为外键提供支持,因为我正努力在数据库编程方面做得更好。问题是,如果删除了作业表中的作业,它会在消息表中留下与其相关的孤立消息。所以外键被介绍给我作为解决方案。
However, I've gotten this when trying to do it, and I'm not sure what it's saying, plus, I'm not even sure which way round I should be setting the restriction, from the job to the messages, or vice versa. :(
但是,我在尝试这样做时已经得到了这个,而且我不确定它在说什么,而且,我甚至不确定我应该设置限制,从作业到消息,或者副作用反之亦然。 :(
Here's the error:
这是错误:
#1452 - Cannot add or update a child row: a foreign key constraint fails (`nzua9c8_tasks`., CONSTRAINT `#sql-2929_701930_ibfk_1` FOREIGN KEY (`id`) REFERENCES `jobs` (`id`) ON UPDATE NO ACTION)
Also, the interface for PHPMyAdmin suggested that when I delete a task, the message ID would be "restricted". I didn't have an option for delete. I want any messages with a "job_id" that matches an id in the jobs table to be deleted too.
此外,PHPMyAdmin的界面建议当我删除任务时,消息ID将被“限制”。我没有删除选项。我想要删除任何与job表中的id匹配的“job_id”的消息。
Thanks for any help offered.
感谢您提供的任何帮助。
3 个解决方案