I am trying to refactor a Django project. I renamed a couple apps and added a new one, as well as shuffled some models around. I want to clear my database and migrations and start fresh, but I am not sure how to accomplish this. Here's what I did:
rm -r myapp/migrations // I ran this for all my apps
python manage.py flush
python manage.py makemigrations myapp // I ran this for all my apps
python manage.py migrate // This errors
I get an error:
django.db.utils.OperationalError: table "myapp_mymodel" already exists
Can anyone tell me what I might be doing wrong?
EDIT: What is the django command to delete all tables? did not work.
sqlite> DELETE FROM table_name; Following is the basic syntax of DROP TABLE. sqlite> DROP TABLE table_name; If you are using DELETE TABLE command to delete all the records, it is recommended to use VACUUM command to clear unused space.
If you want to remove all the data from all your tables, you might want to try the command python manage.py flush . This will delete all of the data in your tables, but the tables themselves will still exist. Save this answer.
Django's migration can be reset by cleaning all the migration files except __init__.py files under each project app directory, followed by dropping the database and creating migration again using python manage.py makemigrations and python manage.py migrate .
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With