Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undo or reset the faked migrations in django

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.

like image 236
n.imp Avatar asked Jul 30 '15 18:07

n.imp


People also ask

How do I reset Django migrations?

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 .

How do I undo all migrations?

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.

What does fake migration do in Django?

--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.

How to delete a Django migrations folder?

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

Is it possible to use --fake in Django migration?

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.

How do I clear the Django database?

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.

Is it possible to fake a migration?

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:


1 Answers

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
like image 133
Alasdair Avatar answered Sep 17 '22 14:09

Alasdair