Jenny
Jenny

Reputation: 76

Django migration delete and update

I have already had some migration files, and I made some changes in the model and did

python manage.py makemigrations
python manage.py migrate

After that in postgresql table django_migrations there is a row indicating I've applied that migration, let's call this migrationA. I deleted the new generated migration file (migrationA), modified a small piece in my model and then did

python manage.py makemigrations
python manage.py migrate

This generate migrationB. I was hoping this can do the same as squashing migration files.

Will this kind of flow cause any trouble? I didn't see any trouble now but want to make sure this is a safe way to do things. In addition, is there any way to revert postgresql to the time before I applied migrationA?

Upvotes: 0

Views: 2370

Answers (1)

Clarity
Clarity

Reputation: 10873

Yes, it will cause trouble. All the migrations are stored in the migrations table and just deleting a migration will produce inconsistencies between your actual migrations and what's recorded.

Before deleting a migration and creating a new one, you need to first revert it by running ./manage.py migrate my_app number_previous_migration_name.

Upvotes: 1

Related Questions