Django: cascade on_delete option not working

2019-07-30 19:17发布

问题:

I am using django 1.2.4 (Confirmed through the shell with import django django.VERSION) and am attempting to use the on_delete=models.SET_NULL setting on a ForeignKeyField but I get the error:

AttributeError: 'module' object has no attribute 'SET_NULL'

This is how I was attempting to use the setting:

relatedRec = models.ForeignKey(Record, null=True, blank=True, on_delete=models.SET_NULL)

The model was already created and I am now trying to alter it. I didnt think that would be a problem but maybe it is...

Am I doing this properly or are there any tircks/issues with what I am trying to do?

Thanks

回答1:

The on_delete argument is new in Django 1.3 which will be released in a couple of weeks (or days, it was projected for January 31, but that date could slip, since there is no release candidate yet).

Current trunk or the Beta 1 of Django 1.3 are perfectly fine for development, but I wouldn't risk using it in production just yet.