-
-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
提交、删除评论时出错:Error 1451 (23000): Cannot delete or update a parent row: a foreign key constraint fails
#835
Comments
你好,你的 Artalk 版本是 v2.8.4 吗,目前这个版本存在问题,暂时已撤回,可以试试降级到 v2.8.3 😢 |
在发现问题后我也尝试降回 v2.8.3,但是似乎还是存在类似的问题。 话说这个问题具体是因为什么?没研究过 Go 不太能看懂 Artalk 的代码。 |
是因为 v2.8.4 错误地给 comments 表字段加上了外键约束,然而之前的版本没有处理维护外键约束,可以尝试手动删除约束规则。 MySQL 和 PgSQL 数据库会出现这个问题,由于我的疏忽,只测试了 SQLite 它没有问题。 |
可以尝试执行以下的 SQL 语句删除外键约束 --删除 comments 表的 page_key 外键约束
ALTER TABLE comments
DROP FOREIGN KEY fk_comments_page;
--删除 comments 表的 user_id 外键约束
ALTER TABLE comments
DROP FOREIGN KEY fk_comments_user;
--删除 pages 表的 site_name 外键约束
ALTER TABLE pages
DROP FOREIGN KEY fk_pages_site; |
在 Navicat 中执行过了以上 SQL 语句,但是在 v2.8.3 上仍然出现了外键约束的问题……? |
用 Navicat 检查一下 comments 表的约束看看有没有删干净 |
好了,现在已经恢复正常了,感谢您不厌其烦的指导 🫡 |
… generation (#835) Add function to delete all foreign key constraints when migration. Leave relationship maintenance to the program and reduce the difficulty of database management. Because there are many different DBs and the implementation of foreign keys may be different, and the DB may not support foreign keys, so don't rely on the foreign key function of the DB system.
你好,v2.8.5 已发布,应该解决了这个问题 :D |
提交、删除评论时 MySQL 数据库出现问题:
The text was updated successfully, but these errors were encountered: