I used my django migrations to migrate my database. One of the migrations was data migrations. But I made a mistake: I didn't save the model). Thus, no change was applied to data. I corrected the .py file that executed the python code for the data migrations. I now want to re-execute it. Is there a way to rollback to the previous version of my database or just running
./manage.py migrate my_app 0004
with 0004 being the file that did the datamigrations does the trick?
You can rollback your migration by using rake db:rollback with different options. The syntax will be different according to your requirements. where n is number of migrations to rollback, counting from latest migration.
Undoing Migrations With migration you can revert to old state by just running a command. You can use db:migrate:undo , this command will revert most the recent migration. You can revert back to the initial state by undoing all migrations with the db:migrate:undo:all command.
There is a solution: run migrations 2 and 3 backwards with ./manage.py migrate my_app 0001 , then delete migration files. If you can't migrate back (e.g. you messed up with your database manually) then you can fake migrate back with ./manage.py migrate my_app 0001 --fake and set up database as it should be manually.
In order to rollback I had to do the following
showmigrations
to see where I ammigrate 0003
(to go one step back)showmigrations
to verify that it worked and I am one version behindmigrate 0004
to migrate correctlyIf 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