djangodjango-admin

Allow null in foreign key to user. Django


I have this model

class Vacancy(models.Model):
    user = models.ForeignKey(User, null=True, blank=True, default = None)
    name = models.CharField(max_length=64)

When in admin i try to creat a vacancy without a user. And it throws an error " club_vacancy.user_id may not be NULL". Am i doing something wrong?


Solution

  • club_vacancy.user_id may not be NULL

    Looks very much like an error from your database, rather than from Django.

    It seems most likely that you added null=True after running manage.py syncdb. You'll need to modify your database schema to allow null values in that column.