On zaterdag 4 augustus 2018 18:03:21 CEST Andréas Kühne wrote: > I don't know how to revert migrations though - I do think it's possible....
Yes, easy. Name the app and migration you want to downgrade to: python manage.py yourapp 0002 This would unapply 0003_new_model, 0004_change_new_model and so on. If you want to unapply all migrations of a given app, then you use "zero": python manage.py yourapp zero This unapplies 0001, 0002 etc ... This is documented at the "migrate" management command[1]. This only works when your migrations have a "reverse" operation coded, where RunSQL[2] and RunPython[3] is concerned, otherwise the system will not know how to unapply the migration. If you want a system that automatically reverts migrations to a set version number of the entire project, then you'll need to create some custom code and your tools of choice will be: - A RunPython migration in the project app, that keeps track of which migrations belong to which version ... or: - You squash migrations when cutting a new release and name them consistently using "-- squashed-name[4]". For example: coolapp/migrations/0001_v1_0_0.py, hotapp/migrations/ 0001_v1_0_0.py, coolapp/migrations/0002_v1_0_3.py With either approach it should be possible to write a management command that gathers all the migrations to unapply and get back to a fixed point in time. But what you really have to be aware of, is that it is destructive: if you added fields to a model and that model has new data in that field during the time it was deployed, rolling back the migration will destroy that new data. So while you can go back, you can't easily go forward again and have that data magically reappear. https://djangopackages.org/grids/g/versioning/ Probably in addition to custom code. -- Melvyn Sopacua -------- [1] https://docs.djangoproject.com/en/2.0/ref/django-admin/#migrate [2] https://docs.djangoproject.com/en/2.0/ref/migration-operations/ #django.db.migrations.operations.RunSQL [3] https://docs.djangoproject.com/en/2.0/ref/migration-operations/ #django.db.migrations.operations.RunPython [4] https://docs.djangoproject.com/en/2.0/ref/django-admin/#cmdoption-squashmigrations-squashed-name -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3452710.b6zlfaCYd4%40fritzbook. For more options, visit https://groups.google.com/d/optout.

