English 中文(简体)
为什么一个Django模型的栏目在现实世界中消失?
原标题:Why would a Django model cascade delete fail in the real world?

鉴于Django模式:


class ContainerOwner(models.Model):
  id = models.IntegerField()

class Container(models.Model):
  owner = models.ForeignKey(ContainerOwner)

如果您在“集装箱拥有者”的物体上打上了.子,就会把该集装箱拥有者拥有的所有“集装箱”。

但是,我发现,在我的实际生活中,“暴动”项目有时会消失。 似乎偶然发生,而且该系统数量庞大。 因此,在“拥有者”被删除之后,你最后拿到“拥有者”没有有效“拥有者”的“拥有者”物体(这是不可能的,集装箱总是拥有集装箱)。

是否有任何人曾看到过这种失败,并能够解释它是如何发生的? 在通过申请或非银服务器删除校车的过程中,这套车能否删除一半。

www.un.org/Depts/DGACM/index_spanish.htm

Updates to question based on answer feedback:

(1) 我们使用我的仪同我的SQL

2) 我们正在使用一个解说,删除一个“拥有者”物体的质子。

3) MySQL支持

4) 我们采取非常共同的行动,将“拥有者”物体的Django查询组全部删除,其所有“拥有者”物体也应删除。 每天发生数十次,我们只是不知有这些孤儿的“集装箱”物体造成申请错误。 在删除的人口中,有很小一部分是失败的,因为删除的0.01%导致一些孤儿。

最佳回答

确实不可能回答你的实际问题,而不知道你的申请详情如下:

  1. Do you have any custom logic in ContainerOwner.delete() or Container.delete()?
  2. Are you using queryset s delete anywhere, on ContainerOwner?
  3. What database are you using??
  4. The general usage pattern in creating/updating/deleting ContainerOwner/Container objects

但最重要的是:

这首先不能在<>数据库上实现,除非你没有外国的关键限制,或你正在使用不支持科索沃制约因素的银(如MySQL + MYISAM)。 如果是前者,你首先应确定这一点。 如果是后者,则考虑转换,这取决于这实际上对你们来说是多么重要。

问题回答

如果其他人在此期间增加了一个集装箱,该集装箱拥有同样的集装箱,而且你不在交易范围之内,则不会删除。 在这种情形下,你应当取得正直。

Also, if you have any code that is outside of django, and there are other, conflicting database constraints, then these will prevent cascading deletion.

检查你的数据库记录,并了解删除的原因。





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签