Reset SQLite database in Django

Issue

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.

Solution

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.

Answered By – vsd

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published