Reputation: 4092
When I run the following command
python manage.py migrate
I receive this error from django so can't step forward in my practice:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 63, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__
self.build_graph()
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 241, in build_graph
self.graph.add_dependency(migration, key, parent)
File "/home/nikhil/testWeb-devEnv/local/lib/python2.7/site-packages/django/db/migrations/graph.py", line 42, in add_dependency
raise KeyError("Migration %s dependencies reference nonexistent parent node %r" % (migration, parent))
KeyError: u"Migration testBolt.0001_initial dependencies reference nonexistent parent node (u'delivery_boy', u'0004_auto_20150221_2011')"
How do I solve this problem?
Upvotes: 73
Views: 101727
Reputation: 1
simply delete all previous migration files except the first "0001_initial.py" migration file, then enter the makemigrations command, and migrate. clearing all previous migrations, the program would make migrations for all changes not in the initial migration without having to reference any conflicting node.
Upvotes: 0
Reputation: 11544
In my case, I had the .py
extension in the dependency module name, like this:
dependencies = [
('dashboard', '0003_auto_20181024_0603.py'),
('auth', '__latest__'),
('contenttypes', '__latest__'),
]
I removed the .py
, changing the line to this
('dashboard', '0003_auto_20181024_0603'),
and that fixed it.
Upvotes: 16
Reputation: 519
This works for me:
find . -type d -name "__pycache__" -exec rm -rf "{}" \;
.sqlite3
python manage.py makemigrations
python manage.py migrate
Basically, all the below steps are common and I think all have gone through these steps but if you're missing the first step i.e., to recreate the virtual environment then must give a try to it.
Upvotes: 0
Reputation: 37
I just uninstalled Django and reinstalled it:
pip3 uninstall Django
pip3 install Django
then migrated
Upvotes: 1
Reputation: 195
Here's how it worked for me:
__pycache__
folders inside every app.__init.py__
inside each app folder.python manage.py makemigrations
python manage.py migrate
python manage.py runserver
Upvotes: 5
Reputation: 4092
Solution - 1
Remove pyc
files from your migrations folder.
Solution - 2
Need to remove that reference from testBolt.0001_initial
by editing migration file.
Solution - 3
Remove the new changes from the models and run python manage.py migrate --fake
Now again modify your models with new changes
Run python manage.py makemigrations
And then again run python manage.py migrate
Upvotes: 69
Reputation: 4671
This worked for me:
Upvotes: 3
Reputation: 21
I had moved around my virtual environment folder.so I moved it back where it was, worked for me.
Upvotes: 2
Reputation: 143
This works for me In your app migrations folder
__init__
)Delete all the files in the migrations (except the __init__
)
python manage.py makemigrations
python manage.py migrate
runserver
Upvotes: 9
Reputation: 4669
KeyError: u"Migration testBolt.0001_initial dependencies reference nonexistent parent node (u'delivery_boy', u'0004_auto_20150221_2011')"
Remove
testBolt.0001_initial
then run migrate again
Upvotes: 4
Reputation: 2249
I tried NIKHIL's solutions with no luck. What did work for me was:
__pycache__
foldersUpvotes: 4
Reputation: 3731
There could be some migration files remaining in the app when you tried the migrate command. First remove all migrations
directories from all the modules. For other cases Nikhil Rane has covered it all.
Upvotes: 0
Reputation: 5094
I had the same problem. In my case, because I played with migrations manually, I forgot to create __init__.py
inside of migrations
folder.
Upvotes: 10
Reputation: 5416
Make sure that you have activated your virtual environment.
Upvotes: 3
Reputation: 19
Go to folder testBolt -> migrations and remove 0001_initial py and pyc files.
Upvotes: -2
Reputation: 113
I had a similar case, running django in windows in a virtual env. In my case the missing dependency was 0001_initial - which was definitely there in the migration folder.
The 'solution' was to remove the pyc files and do another migrate attempt.
Upvotes: 5