I have a Tile model that contains a foreign to a Chip:

class Tile(models.Model):
    name=models.CharField(max_length=NAME_LENGTH)
    chip = models.ForeignKey(Chip)

I find that I get an integrity error if I create a tile that refers to
a chip that has not yet been saved:

>>> c = Chip(name="chip")
>>> t = Tile(name="tile", chip=c)
>>> t.save()
[stack trace omitted]
IntegrityError: chipvision_tile.chip_id may not be NULL

This is reasonable.  So I then saved the chip and then tried to save
the tile, but I still get the integrity error:
>>> c.save()
>>> t.chip
<Chip: xchip>
>>> t.chip.id
5
>>> t.save()
[stack trace omitted]
IntegrityError: chipvision_tile.chip_id may not be NULL

However, if I then reset the chip field of the tile (just by
reassigning t.chip = t.chip) and then save the tile, the save now
works fine:

>>> t.chip = t.chip
>>> t.save()  # this save works!

This seems odd.  Is this expected behavior?

Margie


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to