Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6219043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:42+00:00 2026-05-24T07:42:42+00:00

Given the Django models: class ContainerOwner(models.Model): id = models.IntegerField() class Container(models.Model): owner = models.ForeignKey(ContainerOwner)

  • 0

Given the Django models:


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

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

If you call .delete() on a “ContainerOwner” object it will cascade delete all of the “Container” objects owned by that ‘ContainerOwner’.

But I’ve found that in my real life django project there are times when this cascade delete seems to fail. It seems to occur sporadically and when the system is under a high volume. So you end up with “Container” objects that have no valid “ContainerOwner” after the “ContainerOwner” has been deleted (this should be impossible, ‘Containers’ always have a ‘ContainerOwner’.)

Has anyone seen this type of failure before and can explain how it is occurring? Can the cascade delete get killed halfway in the process of doing the cascade delete by the application or DB server?

Updates to question based on answer feedback:

1) We are using myisam with MySQL

2) We are using a queryset delete to delete a queryset of “ContainerOwner” objects

3) MySQL backend

4) We have a very common action where a Django queryset of “ContainerOwner” objects is deleted in all at once and all of their “Container” objects should also be deleted. This happens dozens of times a day and we are just noticing that there are these orphan “Container” objects causing application errors. It looks like a very very small percentage of the deletes are failing, like 0.01% of deletions lead to having some orphans.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:42:42+00:00Added an answer on May 24, 2026 at 7:42 am

    It’s not really possible to answer your actual question, without knowing a lot more details about your application like:

    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

    But most importantly:

    "Container" objects that have no valid "ContainerOwner" after the "ContainerOwner" has been deleted

    This should not be possible in the first place on the database level, unless you are missing foreign key constraints or you are using a DB which does not support FK constraints (like MySQL + MYISAM). If it’s the former, you should fix that first. If it’s the latter, consider switching, depending on how important this actually is for your app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given: from django.db import models class Food(models.Model): Food, by name. name = models.CharField(max_length=25) class
Given a Django model likeso: from django.db import models class MyModel(models.Model): textfield = models.TextField()
Given a class: from django.db import models class Person(models.Model): name = models.CharField(max_length=20) Is it
Given django models A and B: class A(models.Model): things = models.ManyToManyField('B') class B(models.Model): score
Given: from django.db import models class MyModel(models.Model): ... owners = models.CharField(max_length=255, blank=False) where owners
When I have a given django model class like this: class BaseClass(models.Model): some_field =
I'm struggling with the design of a django application. Given the following models: class
Using Django 1.1.1 In models.py: class Site(models.Model): name = models.CharField(max_length=50) class SiteMonth(models.Model): site =
I have the following Django 1.2 models: class Category(models.Model): name = models.CharField(max_length=255) class Article(models.Model):
If I have two models in Django: class Blog(models.Model): author = models.CharField() class Post(models.Model):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.