Django 没有设置 MySQL ON DELETE = CASCADE [英] Django not setting MySQL ON DELETE = CASCADE
问题描述
我正在使用带有 MySQL 5.5 数据库后端的 Django 1.3.我的假设是 Django 在通过 syncdb 构建数据库时默认模拟相关对象的 ON DELETE CASCADE 效果.但是,检查数据库会发现 ON DELETE 属性实际上设置为RESTRICT".这是一个错误吗?由于我无法删除相关记录,因此在删除具有相关对象的对象时,我不断在 djang-admin 中收到 IntegrityError 消息.
I'm using Django 1.3 with the MySQL 5.5 database backend. My assumption was that Django by default emulates the ON DELETE CASCADE effect for related objects when building the database via syncdb. However, inspecting the database reveals that the ON DELETE property is in fact set to "RESTRICT". Is this a bug? As I'm unable to delete related records I keep getting the IntegrityError message in the djang-admin when deleting an object that has a related object.
谢谢
推荐答案
似乎 Django 1.3.1 出于某种原因未能将 ON DELETE CASCADE 属性应用于表.它可能与在 Windows 上运行的 MySQL-python 1.2.3 接口有关.解决此问题的唯一其他方法是通过 自定义 SQL.
It would seem that Django 1.3.1 for some reason fails to apply the ON DELETE CASCADE property to the table. It could possibly have something to do with the MySQL-python 1.2.3 interface running on Windows. The only other way to resolve this issue is via custom SQL.
这篇关于Django 没有设置 MySQL ON DELETE = CASCADE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!