I have following model:
class Client(models.Model):
user = models.OneToOneField(DjangoUser, unique=True)
address = models.ForeignKey(Address,blank=True)
class Address(models.Model):
(...)
Then I do:
client=Client()
client.address=address #any Address instance
client.save()
And now: how can I remove foreign association key from client?
client.address=None
seem not to work.
To be able to null out a foreign key, it’s not enough to set in
blank. You must also specify thatnull=Trueis also set on the field. See The Difference Between Blank and Null.