On Sat, Jan 4, 2014 at 9:57 AM, Phil Hughes <nicafyl@gmail.com> wrote:
I have a model where a foreign key reference may be undefined when a record is first created. In particular, I have the following in my model seller = models.ForeignKey(User, related_name='+', blank=True, null=True) The form accepts not setting the seller field but I get an Integrity Error exception when I attempt to save it that says escrow_escrow.seller_id may not be NULL I am using SQLite. What did I miss?
Was the null=True restriction in place when you created the table? If you ran syncdb and *then* added the null=True definition, the null=True definition won't be picked up by the database - you'll need to do a table migration. However, it *will* be picked up by forms, as they read the model definition as-is.
Migrating tables is a bit painful on SQLite; it will probably be easier to just drop the table and recreate it. If you need to preserve data in the table, you can use the dumpdata/loaddata management commands.
Yours,
Russ Magee %-)
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAJxq84_fp76gVDgxJoq_KTj8%3DUkZu0-ngex-Pvm36KiOu3A5gw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment