nyergler / effective-django

Documentation on effectively using Django for building web applications.
Other
175 stars 34 forks source link

Authz/n instructions don't work with Django migrations #15

Open nyergler opened 9 years ago

nyergler commented 9 years ago

As reported by Maciej Friedel:

I found solution on problem in Your tutorial. in section Handling Authentication & Authorization (http://effectivedjango.com/tutorial/authzn.html)

in last contacts/models.py correction there is:

owner = models.ForeignKey(User)

but this is not correct and displaying error

because there is migration problem

% python manage.py makemigrations
You are trying to add a non-nullable field 'owner' to contact without a default;
we can't do that (the database needs something to populate existing rows).
Please select a fix:
1) Provide a one-off default now (will be set on all existing rows)
2) Quit, and let me add a default in models.py
Select an option:

the problem resolved this input:

owner = models.ForeignKey(User, null=True, blank=True, default = None)

after successful migration there can be owner = models.ForeignKey(User) but migration needed this default settings