I know that from Django 1.7 I don\'t need to use South or any other migration system, so I am just using simple command python manage.py makemigrations
You can't add reference to table that have already data inside.
Change:
user = models.OneToOneField(User)
to:
user = models.OneToOneField(User, default = "")
do:
python manage.py makemigrations
python manage.py migrate
change again:
user = models.OneToOneField(User)
do migration again:
python manage.py makemigrations
python manage.py migrate
If you are in early development cycle and don't care about your current database data you can just remove it and then migrate. But first you need to clean migrations dir and remove its rows from table (django_migrations)
rm your_app/migrations/*
rm db.sqlite3
python manage.py makemigrations
python manage.py migrate
If you are early into the development cycle you can try this -
Remove/comment that model and all its usages. Apply migrations. That would delete that model and then add the model again, run migrations and you have a clean model with the new field added.
Do you already have database entries in the table UserProfile
? If so, when you add new columns the DB doesn't know what to set it to because it can't be NULL
. Therefore it asks you what you want to set those fields in the column new_fields
to. I had to delete all the rows from this table to solve the problem.
(I know this was answered some time ago, but I just ran into this problem and this was my solution. Hopefully it will help anyone new that sees this)