In my project which is based on django-1.8.2 I was facing some problems with migrations so i ran command
python manage.py migrate --fake
But it faked all the migrations which this command is meant for. But now python manage.py migrate
command is not doing or applying any migration. I want to undo the faked migrations so that I can apply the migrations to database. I want to apply the existing migrations to the database.
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 .
just use rake db:reset , that will drop your database (same as undoing all migrations) and reset to the last schema. UPDATE: a more correct approach will be using rake db:migrate:reset . That will drop the database, create it again and run all the migrations, instead of resetting to the latest schema.
--fake-initialAllows Django to skip an app's initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations.
Another option is to use Django’s manage.py command to clear the whole database for us. The command is python manage.py flush. Again, after using this command, we have to delete all the migrations folders and then make the new migrations. Revert a Django App back to its old migrations
be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly. So I suggest you to simply remove faked migrations from django_migrations table.
Another option is to use Django’s manage.py command to clear the whole database for us. The command is python manage.py flush. Again, after using this command, we have to delete all the migrations folders and then make the new migrations.
For each app, you can fake the migrations back to where they were before you faked them. where 00XX_last_migration is the last migration that you actually ran for your app myapp. Or, if you haven't actually run any migrations for that app yet:
For each app, you can fake the migrations back to where they were before you faked them.
python manage.py migrate --fake myapp 00XX_last_migration
where 00XX_last_migration
is the last migration that you actually ran for your app myapp
.
Or, if you haven't actually run any migrations for that app yet:
python manage.py migrate --fake myapp zero
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