How to make a Django ForeignKey optional

Looks like you need to have both blank=True and null=True to make a ForeignKey optional in a django model…

4 Responses to “How to make a Django ForeignKey optional”

  1. Italo Maia Says:

    Thanks ; )

  2. Paul Holt Says:

    Thanks Rachel

  3. Beau Says:

    Rachel, pretty awesome tip, thanks!!

  4. stretch Says:

    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;

Leave a Reply