本文介绍了Django没有设置MySQL ON DELETE = CASCADE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Django 1.3与MySQL 5.5数据库后端。我的假设是Django默认情况下通过syncdb构建数据库时模拟相关对象的ON DELETE CASCADE效果。但是,检查数据库会显示ON DELETE属性实际上设置为RESTRICT。这是一个bug吗?由于我无法删除相关记录,因此在删除具有相关对象的对象时,会继续在djang-admin中获取IntegrityError消息。



谢谢

解决方案

似乎Django 1.3.1由于某些原因无法将ON DELETE CASCADE属性应用于表。它可能与Windows上运行的MySQL-python 1.2.3接口有关。解决此问题的唯一方法是通过。


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.

Thanks

解决方案

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:00