nikitz
nikitz

Reputation: 1091

Recreate applied migration in Django

I have a situation where on an important environment for my application a migration file was generated with the latest code changes and applied to the database. Since there were several changes on the models the name was auto generated with a timestamp.

Unfortunately the file was lost after that and not committed to a version control system.

Now I'm pretty sure that using the same version from which this migration file was created I can recreate exactly the same migration file, but it will carry different name (with different timestamp) and will cause Django to fail (since the migration removes a table).

In this situation where I know the newly generated file is matching the one that is lost but applied to the DB can I just rename the new file to match the name of the one that was applied - so that Django can recognise the migration as applied? I'm not sure how Django evaluates applied migrations and recognising the files.. Is it only by the name of the file like it is stored in the migration history table?

Also is there a better solution from the one I'm thinking about?

Upvotes: 0

Views: 289

Answers (1)

Marco
Marco

Reputation: 2834

You can rename the newly generated migrations to the one in the django_migrations table. That should already be enough and you are good to go.

Check out Migrations - Version control where is described that Django cares about the filename of the migrations.

You can and should test that in your development environment.

Upvotes: 1

Related Questions