Code

#19931 closed Bug (needsinfo)

Deleting from Site model won't cascade delete related models

Reported by: james_lin Owned by: nobody
Component: contrib.sites Version: 1.4
Severity: Normal Keywords: cascade, delete, sites
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have asked this in Stackoverflow and received no valid response, so I think I might raise the issue here.

I have a django project currently hosting multiple sites, and now I need to split them into different projects with different databases.

So I cloned the project and thinking delete the records in Site model will cascade delete all data related to the sites I am deleting and leaving the ones that relates to the site record I am keeping.

I have the following code in management command to delete the sites:

Site.objects.filter(~Q(domain=options.get("domain"))).delete()

But I am getting error like this:

django.db.utils.IntegrityError: update or delete on table "django_site" violates foreign key constraint "core_staticpage_site_id_fkey" on table "core_staticpage"
DETAIL:  Key (id)=(4) is still referenced from table "core_staticpage".

More info:
This error applies to ForeignKey and ManyToManyField
Django version is 1.4.3
No on_delete overwrite were found in project

Attachments (0)

Change History (1)

comment:1 Changed 16 months ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to needsinfo
  • Status changed from new to closed

There isn't anything that Site does differently from any other model, so I don't think this is a bug in Django. I'm guessing this has to do with whatever this "core_staticpage" table/model is, but without seeing that I can't be sure.

If you can provide a minimal test case that reproduces the problem without this external dependency please feel free to reopen the ticket, but for now I'm going to close it as I'm fairly sure this doesn't represent a bug with Django.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.