45👍
Delete database and delete migration files (.py
and .pyc
) in migrations
directory of your app (don’t delete __init__.py
file). Then run python manage.py makemigrations app
and python manage.py migrate
.
5👍
I had the same issue, using Django 1.10, here is what I did, I deleted the database sqlite file, deleted the pycache folders inside each of the apps, deleted all files inside the migrations folder for each app , except the init.py file, and then ran python manage.py makemigrations
and python manage.py migrate
. Also note that because you deleted the database you will have to create a new superuser using python manage.py createsuperuser
. Hope this helps
3👍
For me, just
python manage.py flush
deleted old db contents, so i was able to create records anew in Django 2.1.4.
Don’t forget to create new superuser:
python manage.py createsuperuser
- Relation does not exist error in Django
- How to describe parameters in DRF Docs
- Django south: changing field type in data migration
1👍
This may help you if you want to clear sqlite3 DB follow these steps.
- Delete migrations files except init.py
- Delete dbsqlit3 file
- Then type
python/python3 manage.py migrate
- Then make changes in your models
- Type
python/python3 manage.py makemigrations
- Type
python/python3 manage.py migrate
- Then you have to create new superuser by just typing
python/python3 manage.py createsuperuser
. you should use new name not old user name
- How to have a link in label of a form field
- Why use Django's collectstatic instead of just serving the files directly from your static directory?
- Why does Django South require a default value when removing a field?
- Django south: changing field type in data migration
0👍
Do not delete your database file!
Its correct to delete migration files and then run flush but deleting sqlite database file is wrong. This worked to me every time. If you are using other database, it will save you a lot of work and preparations.
- delete all “.py” and “.pyc” files manually
- python manage.py flush
type “yes” to confirm - python manage.py makemigrations
- python manage.py migrate
- Django models across multiple projects/microservices. How to?
- UnicodeEncodeError:'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)