Update:  in the SQL for the Title table,

CREATE TABLE "core_title" (
 ...
"supplier_id" integer NULL,
);

Two things to note:
1. the SQL explicitly allows the supplier field to be NULL
2. the 'REFERENCES "core_contact" ("id") clause is conspicuously
absent


On Jan 23, 6:12 pm, Wyley <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I have a model with a ForeignKey field that sets null=True:
>
> class Title(models.Model):
>     #...
>     supplier = models.ForeignKey(Contact, verbose_name='Supplier',
> null=True)
>
> ...but when I try to save an instance without a supplier:
>
> >>> t = Title()
> >>> t.save()
>
> [complete Traceback below...]
> IntegrityError: core_title.supplier_id may not be NULL
>
> Even weirder, this error does not occur when I save Title objects
> without a supplier in some of my unit tests -- at least, all tests
> succeed.
>
> Is there some reason that Django would implicitly forbid this field to
> be NULL, despite my having explicitly set null=True in the model?
>
> I am using sqlite3 and Django 0.96, if that's relevant.
>
> Thanks,
> Richard
>
> -----------------------------------------------------------------------------------------------------------------------
> Traceback (most recent call last):
>   File "<console>", line 1, in <module>
>   File "/var/lib/python-support/python2.5/django/db/models/base.py",
> line 238, in save
>     ','.join(placeholders)), db_values)
>   File "/var/lib/python-support/python2.5/django/db/backends/util.py",
> line 12, in execute
>     return self.cursor.execute(sql, params)
>   File "/var/lib/python-support/python2.5/django/db/backends/sqlite3/
> base.py", line 93, in execute
>     return Database.Cursor.execute(self, query, params)
> IntegrityError: core_title.supplier_id may not be NULL
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to