On 9 Sep 2010, at 12:04, bagheera wrote: >> On Sep 8, 11:14 pm, maroxe <bachir...@gmail.com> wrote: >>> Hi, In my models I want to have an optional field to a foreign key. I >>> tried this: >>> >>> field = models.ForeignKey(MyModel, null=True, blank=True, >>> default=None) >>> >>> But i am getting this error: >>> >>> model.mymodel_id may not be NULL
I think the error is that SQLite treats columns with defaults as NOT NULL. As far as I can see, you don't need the `default=None` in your model declaration. Change it to: field = models.ForeignKey(MyModel, null=True, blank=True) -- I have multiple apps using SQLite that do exactly this, so to quote an earlier post, "this should just work (TM)" HTH Regards, Carlton -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.