#19931: Deleting from Site model won't cascade delete related models
-------------------------------+------------------------------------
     Reporter:  james_lin      |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  contrib.sites  |    Version:  1.4
     Severity:  Normal         |   Keywords:  cascade, delete, sites
 Triage Stage:  Unreviewed     |  Has patch:  0
Easy pickings:  0              |      UI/UX:  0
-------------------------------+------------------------------------
 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

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19931>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to