Package: vmigration-helper
Van's Migration HelperDjango commands to help with running Django migrations.InstallationAdd the dependency to your environment:pip install vmigration-helperAdd the appvmgration_helper.apps.VMigrationHelperConfigto your list of installed apps in your settings:INSTALLED_APPS = [
  ...
  'vmigration_helper.apps.VMigrationHelperConfig',
  ...
]Commandsmigration_recordsShows existing migration records in yourdjango_migrationtable.> python manage.py migration_records --format csv
ID,Applied,App,Name
175,2021-06-13T20:41:28.683900+00:00,contenttypes,0001_initial
176,2021-06-13T20:41:28.717886+00:00,auth,0001_initial
177,2021-06-13T20:41:28.742930+00:00,admin,0001_initial
178,2021-06-13T20:41:28.761938+00:00,admin,0002_logentry_remove_auto_add
179,2021-06-13T20:41:28.770319+00:00,admin,0003_logentry_add_action_flag_choices
180,2021-06-13T20:41:28.791287+00:00,contenttypes,0002_remove_content_type_name
...
192,2021-06-13T20:41:28.991814+00:00,sessions,0001_initialThese are the records of migrations applied. The fields indicate:ID - the ID of the recordApplied - when the migration was appliedApp - name of the Django appName - name of the migrationOptional parameters:--format (console | csv)print the info in CSV or friendlier console format (default)--connection-name {connection}the connection name to use (default isdjango.db.DEFAULT_DB_ALIAS)migration_current_idShows the ID of the latest migration record in yourdjango_migrationtable.> python manage.py migration_current_id
192192 is the ID of the latest record as shown above.Optional parameters:--connection-name {connection}the connection name to use (default isdjango.db.DEFAULT_DB_ALIAS)migration_rollbackRoll-back (unapply) previously applied migrationsafter(but not including) the migration ID provided.> python manage.py migration_rollback 176The above will rollback migrations after0001_initialof theauthapp:python manage.py migrate sessions zero
Operations to perform:
  Unapply all migrations: sessions
Running migrations:
  Rendering model states... DONE
  Unapplying sessions.0001_initial... OK

python manage.py migrate auth 0001_initial
Operations to perform:
  Target specific migration: 0001_initial, from auth
Running migrations:
  Rendering model states... DONE
  Unapplying auth.0012_alter_user_first_name_max_length... OK
  Unapplying auth.0011_update_proxy_permissions... OK
  Unapplying auth.0010_alter_group_name_max_length... OK
  Unapplying auth.0009_alter_user_last_name_max_length... OK
  Unapplying auth.0008_alter_user_username_max_length... OK
  Unapplying auth.0007_alter_validators_add_error_messages... OK
  Unapplying auth.0006_require_contenttypes_0002... OK
  Unapplying auth.0005_alter_user_last_login_null... OK
  Unapplying auth.0004_alter_user_username_opts... OK
  Unapplying auth.0003_alter_user_email_max_length... OK
  Unapplying auth.0002_alter_permission_name_max_length... OK

python manage.py migrate contenttypes 0001_initial
Operations to perform:
  Target specific migration: 0001_initial, from contenttypes
Running migrations:
  Rendering model states... DONE
  Unapplying contenttypes.0002_remove_content_type_name... OK

python manage.py migrate admin zero
Operations to perform:
  Unapply all migrations: admin
Running migrations:
  Rendering model states... DONE
  Unapplying admin.0003_logentry_add_action_flag_choices... OK
  Unapplying admin.0002_logentry_remove_auto_add... OK
  Unapplying admin.0001_initial... OKOptional parameters:--connection-name {connection}the connection name to use (default isdjango.db.DEFAULT_DB_ALIAS)--dry-runwill print the commands but will not actually run them--migrate-cmd <command to run migrations>sets the command to run migrations with. The command must accept
the app and migration name as the{app}and{name}placeholders, respectively.For example:--migrate-cmd "pipenv run python manage.py migrate {app} {name}"can be used to have the command run migrations usingpipenv.For example:> pipenv run python manage.py migration_rollback 0 --dry-run --migrate-cmd "pipenv run python manage.py migrate {app} {name}"
pipenv run python manage.py migrate sessions zero
pipenv run python manage.py migrate auth 0001_initial
pipenv run python manage.py migrate contenttypes 0001_initial
pipenv run python manage.py migrate admin zero
pipenv run python manage.py migrate auth zero
pipenv run python manage.py migrate contenttypes zeromigration_deleteDeletes an entry from Django's migration records. This command should be
used only as a last resort to fix up migration records that cannot be rolled back. No migration up/down is performed;
the record is simply removed fromdjango_migrations.NOTE also that migrations that depend on the record being deleted will be "broken" after the deletion, so this
command should only be run on "leaf" migration records unless you plan to also delete other migration records that
depend on the one being deleted.python manage.py migration_delete myapp 0003_some_migration
Confirm deletion of myapp:0003_some_migration (yes or no): yesThe command above deletes the migration0003_some_migrationfor the appmyapp(after
getting confirmation).To delete without confirmation, use the--yesoption:python manage.py migration_delete myapp 0003_some_migration --yesOptional parameters:--connection-name {connection}the connection name to use (default isdjango.db.DEFAULT_DB_ALIAS)--yeswill proceed to deleting the record without asking for confirmationIdeas for automationHere's an idea for automating the deployment of your Django app using these utilities:Deploy new codeRunmigration_current_idand capture the current IDRun migration normallyRun your automated tests normallyIf tests pass, you're done!If tests fail, and you need to rollback, runmigration_rollback <captured ID>