I am very new to django and was able to finish the tutorial on djangoproject.com without any errors. I am now going through the Django REST framework tutorial found at http:
I faced this problem and this is how I solved it.
1) Delete all the migration records from your app's migration directory. These are files named 0001_,0002_,0003_ etc. Be careful as to not delete the _init__.py file.
2) Delete the db.sqlite3 file. It will be regenerated later.
Now, run the following commands:
python manage.py makemigrations appname
python manage.py migrate
Be sure to write the name of your app after makemigrations. You might have to create a superuser to access your database again. Do so by the following
python manage.py createsuperuser
I did the following
python manage.py makemigrations
python manage.py migrate
It renewed the database and fixed the issues without affecting my project. Please note you might need to do python manage.py createsuperuser
because it will affect all your objects being created.
In my case, in admin.py
I was querying from the table in which new ForeignKey
field was added. So comment out admin.py
then run makemigrations and migrate command as usual. Finally uncomment admin.py
.
You did not migrated all changes you made in model. so
1) python manage.py makemigrations
2) python manage.py migrate
3) python manag.py runserver
it works 100%
I simple made a careless mistake of forgetting to actually apply the migration (migrate) after making migrations. Writing this just in case anyone might make the same mistake.
I think you skipped this steps...run the following commands to see if you had forgotten to execute them...it worked for me.
$ python manage.py makemigrations
$ python manage.py migrate
Thank you.