I have same problem with sqlite. Try another database. Django devs suggest
postgres.
--
Linux user
>> 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