1👍
✅
This problem arises when a foreign key is added to a model, and the model is migrated using south.
Most of the time you do not want to have any null ForeignKey.
Personally, if I ever need to add such a foreign key, I assign it to a default User
(mostly the root
superuser).
-
Add the ForeignKey field as you have done it and do
./manage.py schemamigrate app
. South gives an option to specifiy the default on the command line. In this case, your default would beUser.objects.get(username="root")
-
Otherwise, if you are fine with having null foreign keys, then following definition should work.
class Question(models.Model): q_user = models.ForeignKey(User, null=True, blank=True, default=None)
Source:stackexchange.com