#28141: When have null=True inside ForeignKey, Django don't to do CASCADE
Operation
even passing on_delete=models.CASCADE. [using PostgreSQL]
-------------------------------------+-------------------------------------
Reporter: mateuspadua | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ForeignKey null | Triage Stage:
True PostgreSQL | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by mateuspadua:
Old description:
> Example:
>
> from cms.models import Page
>
> class OfferingPlugin(CMSPlugin):
> image = VersatileImageField(upload_to=unique_upload,
> ppoi_field='ppoi')
> ppoi = PPOIField()
> title = models.CharField(max_length=50)
> subtitle = models.CharField(max_length=140)
> link_copy = models.CharField(max_length=20)
> link_address = models.ForeignKey(Page, blank=True, null=True,
> on_delete=models.CASCADE) ** -> dont work because has null=True**
>
> ....
>
> page = Page.objecs.first()
>
> If I to try delete a Page instance, for example page.delete() the error
> bellow will occur:
>
> .....
>
> IntegrityError: insert or update on table "offering_offeringplugin"
> violates foreign key constraint
> "offering_offering_cmsplugin_ptr_id_9a9e9998_fk_cms_cmsplugin_id"
> DETAIL: Key (id)=(10) is still referenced from table
> "offering_offeringplugin".
New description:
Example:
{{{
from cms.models import Page
class OfferingPlugin(CMSPlugin):
image = VersatileImageField(upload_to=unique_upload,
ppoi_field='ppoi')
ppoi = PPOIField()
title = models.CharField(max_length=50)
subtitle = models.CharField(max_length=140)
link_copy = models.CharField(max_length=20)
link_address = models.ForeignKey(Page, blank=True, null=True,
on_delete=models.CASCADE) ** -> dont work because has null=True**
....
page = Page.objecs.first()
}}}
If I to try delete a Page instance, for example page.delete() the error
bellow will occur:
.....
IntegrityError: insert or update on table "offering_offeringplugin"
violates foreign key constraint
"offering_offering_cmsplugin_ptr_id_9a9e9998_fk_cms_cmsplugin_id"
DETAIL: Key (id)=(10) is still referenced from table
"offering_offeringplugin".
--
--
Ticket URL: <https://code.djangoproject.com/ticket/28141#comment:1>
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/069.1e24db5855afb65a35ea815a26e3afa8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.