Hi everyone,
I’m currently facing a rather tricky issue with Django migrations and would appreciate any insights or advice.
The Setup:
I work on a Django project and use Git for version control. On my local machine, I run a Virtual Python Environment where I’ve installed all the required dependencies. I’ve read that it’s a good practice to have all my own migration files versioned in Git since they precisely document the evolution of my database schema.
The Situation:
On my primary computer, I’ve been regularly updating Python and Django over time. As a result, new migrations for Django’s built-in auth app were generated repeatedly—for instance, a migration that alters the first_name field from 30 to 150 characters (specifically, the 0012_alter_user_first_name_max_length migration). These migration files are part of the installed Django package in my virtual environment and are not included in my Git repo.
Now, I’ve cloned this Git repo on another computer and installed all the dependencies from the requirements.txt file. Both systems are configured to use the same MySQL database over the network. However, on the new system, only the initial migration files exist—where the final state of the models is defined directly—without the step-by-step migration history that evolved on my primary computer.
When I try to run the project, I encounter the following error:
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration api.0001_initial dependencies reference nonexistent parent node ('auth', '0012_alter_user_first_name_max_length')
In plain terms, this means that on my main computer, due to Django updates, an auth migration (namely 0012_alter_user_first_name_max_length) was generated, while on the new system that migration file doesn’t exist. Consequently, one of my own migrations in the API app references a migration node (auth.0012_alter_user_first_name_max_length) that isn’t present on the new machine.
My Question:
How can I handle this scenario? It should be possible for the same Django project to run on multiple systems without encountering such migration errors. I would be thankful for any suggestions or solutions to resolve these dependency discrepancies.
Thanks everyone,
Alex