geekchick77: (Default)
[personal profile] geekchick77
I am working on a large app (hundreds of migrations) and it is becoming unwieldy. There are options for not running migrations when unit testing, but it'd be nice not to need to use them. Plus some of the old migrations reference old code I'd like to be able to delete.

I tried running squashmigrations, but the resulting migration file had errors when I tried to run it on a clean DB.

So, I decided to do the more drastic method of deleting and recreating migrations.

WARNINGS:
  1. ALL databases must be at the same migration level before you begin.
  2. If you have a custom user model, do NOT delete the migration that creates it. You can safely delete subsequent migrations.
  3. If you have data migrations, you need to maintain those.

Procedure for app that contains the custom user (e.g. if app name is "users"):
  1. Ensure all databases (local, staging, production, etc.) are at the same migration level.
  2. Create backups of all your databases.
  3. Save the code for any data migrations in a temporary file.
  4. Delete migration files from 0002 upward (assuming 0001 created the custom user) and commit to git
  5. delete from django_migrations where app='users' and name NOT LIKE '0001%';
  6. python manage.py makemigrations users
  7. Recreate any data migrations.
  8. Verify that migrations run successfully on a clean database.
  9. python manage.py migrate users --fake # Run locally
  10. Commit new migrations.
  11. Push changes to all other systems and on each run: python manage.py migrate users --fake

Procedure for apps in general (e.g. "myapp"):
  1. Ensure all databases (local, staging, production, etc.) are at the same migration level.
  2. Create backups of all your databases.
  3. Save the code for any data migrations in a temporary file.
  4. Delete migration files for myapp and commit to git.
  5. delete from django_migrations where app='myapp';
  6. python manage.py makemigrations myapp
  7. Recreate any data migrations.
  8. Verify that migrations run successfully on a clean database
  9. python manage.py migrate myapp --fake # Run locally
  10. Commit new migrations.
  11. Push changes to all other systems and on each run: python manage.py migrate myapp --fake
From:
Anonymous (will be screened)
OpenID (will be screened if not validated)
Identity URL: 
User
Account name:
Password:
If you don't have an account you can create one now.
Subject:
HTML doesn't work in the subject.

Message:

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org


 
Notice: This account is set to log the IP addresses of everyone who comments.
Links will be displayed as unclickable URLs to help prevent spam.

Profile

geekchick77: (Default)
Jessamyn Smith

November 2016

S M T W T F S
  12345
6789101112
13141516171819
20212223242526
272829 30   

Style Credit

Expand Cut Tags

No cut tags
Page generated Mar. 24th, 2017 08:00 pm
Powered by Dreamwidth Studios