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 9226793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:54:55+00:00 2026-06-18T04:54:55+00:00

I have a general question about designing Django models and considering the effect that

  • 0

I have a general question about designing Django models and considering the effect that has on a cascade delete. Suppose the following simple design of an Asset Management app.

class Asset(models.Model):
    aquire_date = models.DateField()
    cost = models.DecimalField(max_digits=16, decimal_places=2)
    description = models.CharField(max_length=30)
    account = models.ForeignKey(Account)
    vendor = models.ForeignKey(Vendor)
    department = models.ForeignKey(Department)

class Vendor(models.Model):
    name = models.CharField(max_length=70)
    city = models.CharField(max_length=50
    phone = PhoneNumberField()
    email = models.EmailField()

class Account(models.Model):
    account_number = models.IntegerField()
    description = models.CharField(max_length=50)

class Department(models.Model):
    number = models.IntegerField(unique=True)
    name = models.CharField(max_length=50)

So each Asset has 3 ForeignKey fields to other tables. Reading the Django documentation it says ‘any objects which had foreign keys pointing at the object to be deleted will be deleted along with it’. I read that to mean if I delete a Department object, the Asset object, or objects, the ForeignKey is referring to will be deleted as well. But if I delete an Asset, the Department, Vendor, and Account remains.

Is that the correct way to understand cascade deletes in Django?

What I would prefer is

  • when an Asset is deleted, no department, vendor, or account is deleted;
  • when a Department is deleted, no Asset is deleted, but all ForeignKey fields that point to that Department are set to null.

Is that possible?

  • 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-06-18T04:54:56+00:00Added an answer on June 18, 2026 at 4:54 am

    Yes, your understanding is correct.

    Solution: When creating a model ForeignKey field, supply on_delete=django.db.models.SET_NULL. You need to combine this with null=True to allow this because the default is False.

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

Sidebar

Related Questions

I have a general question about debugging a .NET process that has been built
I have a general question about rails controllers/models: I have a model Providers, that
I have a general question about the new Django 1.3 static file framework. I
I have a general question about the way that database indexing works, particularly in
I have a general question about Hibernate that I'm batteling with. I have class
I have a general question about jQuery. Lets say I have the following code:
I have a general question about Django forms (specifically, a contact form) when it
I have a general question about how .dll/.libs are suppose to be used. I
I have a general question about interpreters of functional languages: Are there actually any
i have a general question about how sql server evaluates the joins.The query is

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.