'How do I manage Django migrations when commiting changes from local development to remote?

During Django development, I have to create many migrations to get to what I'm looking for. For example, I might change the name of a field and later decide to set it back to what it was. So a lot of my migrations are just toying with the ORM.

I assume I don't need them all to show up in the remote repo (which might be a wrong assumption!).

I know excluding the migrations via .gitignore is not the right way. Also can't include random ones in commits as they are all linked to one another.

So far, I squash my migrations each time I made changes:

squashmigrations app_label [start_migration_name] migration_name

and then commit.

What would be a better solution?



Solution 1:[1]

I think your solution is good.

Another solution, if your changes are just local, is to manually delete the new migrations and run makemigrations again.

Last but not least, if your concern is performance, the documentation says you shouldn't worry:

You are encouraged to make migrations freely and not worry about how many you have; the migration code is optimized to deal with hundreds at a time without much slowdown.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eduardo Tolmasquim