99π
- Delete the sqlite database file (often
db.sqlite3
) in your django project folder (or wherever you placed it) - Delete everything except
__init__.py
file frommigration
folder in all django apps (eg:rm */migrations/0*.py
) - Make changes in your models (
models.py
). - Run the command
python manage.py makemigrations
orpython3 manage.py makemigrations
- Then run the command
python manage.py migrate
.
Thatβs all.
If your changes to the models are not detected by makemigrations
command, please check this answer
14π
rm -f tmp.db db.sqlite3
rm -r my-app/migrations
python manage.py makemigrations
python manage.py migrate
Removes the database.
Removes the migrations from your app.
Re-runs the migrations. Note: you could also do: python manage.py makemigrations my-app
Migrate changes.
- [Django]-Alowing 'fuzzy' translations in django pages?
- [Django]-How do I migrate a model out of one django app and into a new one?
- [Django]-How can I resolve 'django_content_type already exists'?
0π
You can just delete your sqlite file.
Regarding your question, you should use Django migration system to do database changes for you project using makemigrations and migrate commands
- [Django]-Django: ImproperlyConfigured: The SECRET_KEY setting must not be empty
- [Django]-CORS error while consuming calling REST API with React
- [Django]-In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited?
0π
To do everything in one go, run all below commands in a shell script (Linux flavors) or in a batch file (Windows). and run that script where your manage.py
exists:
find . -path "*/migrations/*.py" -not -name "__init__.py" -delete
find . -path "*/migrations/*.pyc" -delete
find . -path "*.sqlite3" -delete
python manage.py makemigrations
python manage.py migrate
python manage.py migrate
python manage.py shell -c "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'admin@example.com', 'adminpass')"
I prefer them running by copy-pasting directly in one go. make sure to change superuser credentials.
Noteβ This will DELETE all databases and their corresponding migrations
- [Django]-Django: Hide button in template, if user is not super-user
- [Django]-Trying to migrate in Django 1.9 β strange SQL error "django.db.utils.OperationalError: near ")": syntax error"
- [Django]-Django β makemigrations β No changes detected