Reputation: 101
I get the following error when I run any python manage.py function:
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration auth.0010_user_following dependencies reference nonexistent parent node ('accounts', '0002_auto_20180615_2021')
It happened after I tried to reset my migrations by manually deleting the migration files in the migration folders (except the init files - no other files are left in the migration folders).
I have tried dropping the database with python manage.py flush, which also doesn't run.
Any suggestions? Thanks!
SOLUTION: After a week of google search I ended up reconstructing the referenced migration files manually using the documentation: https://docs.djangoproject.com/en/2.0/howto/writing-migrations/
After that the manage.py migrate and makemigration functions worked again. Never delete migration files without taking a backup first!
Upvotes: 7
Views: 5524
Reputation: 1
i am just uninstalled my current Django then re-installed its worked for me
pip3 uninstall Django pip3 install Django
Upvotes: 0
Reputation: 189
I faced the exact same error, and found the constructing the whole database a little complicated I found a way to simply delete the whole database and reload it , (if its useful for you) using the following commands:
Step 1:
find . -path "/migrations/.py" -not -name "init.py" -delete
find . -path "/migrations/.pyc" -delete
Step 2:
Delete the database (sqlite3 in my case)
Step 3: Run
python manage.py makemigrations
python manage.py migrate
They should now run successfully
Upvotes: 2
Reputation: 131
If you have manually deleted your migrations folder, here are options to directly get them back instead of manually re-creating them. Can't imagine the pain.
Reset that deletion
To get them back you can do a git reset on the deleted folder.
git checkout -- initial/path/to/migrations
This should recover them if they were being tracked. This also assumes changes were not yet commited. If they were commited, see this answer
In case the migrations were .gitignored
If the migrations were not tracked by git, you can result to get a clean working tree where django hadn't indexed the run migrations
python manage.py makemigrations && python manage.py migrate
The above option will work if the changes were unpushed to the remote. Otherwise, you'll have to checkout a commit made before the deletions.
The provided options assume you were using git
Upvotes: 0
Reputation: 728
Unfortunately, manually deleting migrations doesn't reset them. The database knows which migrations have been run, and the error you're seeing is from Django trying to check whether the state of the models in your models modules matches the state of the migrations that have been run (which is to say, whether or not you need to create migrations to match) and also whether there are migrations that have been created but not run--these cases would create warnings. In trying to check these things, it tries to load migrations and can't find any of them.
If you want to reset your migrations, and just have a single migration per app to go from an empty database to your current schema in a single step, I recommend using the squash migrations command. You'll need to have the migrations files back first, though.
Alternatively, if you do want to drop and re-create the database altogether, you'll need to do that outside of the management commands, since those do the above checks when they run. Then you can have an empty database and run ./manage.py makemigrations
and you'll get initial migrations that represent models as they are.
Upvotes: 3
Reputation: 101
SOLUTION: After a week of google search I ended up reconstructing the referenced migration files manually using the documentation: https://docs.djangoproject.com/en/2.0/howto/writing-migrations/
After that the manage.py migrate and makemigration functions worked again. Never delete migration files without taking a backup first!
Upvotes: 3