This entry was posted on Friday, October 6th, 2006 at 11:12 am and is filed under Django. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
15 Responses to “How to make a Django ForeignKey optional”
I also noticed I had to redefine the foreign key column in my database (MySQL) to accept NULL values, since it had already been created before I added null=True:
alter table articles_article change category_id category_id integer NULL;
Just when you need the information quickly without too much waffle, up pops a blog like this and does just the job – many thanks! Stretch’s comment helped as well, since I had already created the table without the null-accepting columns.
Thanks ; )
Thanks Rachel
Rachel, pretty awesome tip, thanks!!
Thanks, that just helped me a bunch!
I also noticed I had to redefine the foreign key column in my database (MySQL) to accept NULL values, since it had already been created before I added null=True:
alter table articles_article change category_id category_id integer NULL;
Awesome, I was looking exactly for how to do this, and found this blog entry. It worked like a charm. Thanks a ton.
Thanks for this! Helped a lot.
Thanks Rachel, that was annoying me to no end!
Me too, saved! Thanks!
Thanks a bunch, Stretch was what I needed
Thanks
Its not working for me, i still get an integrity error
syncdb again ^^
Great tip!
Just when you need the information quickly without too much waffle, up pops a blog like this and does just the job – many thanks! Stretch’s comment helped as well, since I had already created the table without the null-accepting columns.
Thanks. Also if manage.py synchdb doesn’t work you should drop all those tables by doing a python.exe manage.py sqlclear appname > droptables.sql
shell> mysql -u userid -p DBName < droptables.sql