Getting ForeignKey not to CASCADE, SET NULL not working (postgresql)

1,026 views
Skip to first unread message

mike

unread,
Aug 19, 2011, 9:35:06 AM8/19/11
to Django users
I can get the set null on a foreign key to work.

in my model I have this:

leaguteTypeId = models.ForeignKey(LeagueType,null=True,
db_column='leaguetype', on_delete=models.SET_NULL)


This is what is postgresql dumps:
ALTER TABLE ONLY league
ADD CONSTRAINT league_leaguetype_fkey
FOREIGN KEY (leaguetype) REFERENCES leaguetype(id) DEFERRABLE
INITIALLY DEFERRED;

This is what it should be:
ALTER TABLE League
ADD CONSTRAINT league_leaguetype_fkey
FOREIGN KEY (leaguetype) REFERENCES leaguetype (id)
ON UPDATE CASCADE
ON DELETE SET NULL

django version 1.3 postgresql 8.4
any ideas ?

thanks

Landy Chapman

unread,
Aug 19, 2011, 11:53:38 AM8/19/11
to Django users

mike

unread,
Aug 19, 2011, 12:03:06 PM8/19/11
to Django users
thanks for the links. I did come across those issues as well. But
the
main issue is that no SET NULL contraint is being set on the
database ... Django does do it, but
if someone deletes an item using the cli, the database will not do the
right thing since
the sql being generated ignores the SET NULL constraint.

thanks again,

mike

On Aug 19, 10:53 am, Landy Chapman <landy.chapm...@gmail.com> wrote:
> Have a look:
>
> -http://old.nabble.com/Should-postgresql-cascade-after-truncate-td3188...
>
> -  https://code.djangoproject.com/ticket/11665
>
> http://groups.google.com/group/django-developers/browse_thread/thread...
Reply all
Reply to author
Forward
0 new messages