ammy
ammy

Reputation: 648

django.db.migrations.exceptions.NodeNotFoundError

When i run makemigrations command, i got this error:

Traceback (most recent call last):
 ...
django.db.migrations.exceptions.NodeNotFoundError: Migration products.0002_auto_20160618_1143 dependencies reference nonexistent parent node (u'products', u'0001_initial')

Upvotes: 29

Views: 36717

Answers (6)

Ibraheem_Khaleel
Ibraheem_Khaleel

Reputation: 1

If you recently deleted an app and trying the migrations. Then better : Delete the file product.0002_auto_20160618_1143 migration file. and again run the following commands:

1.python manage.py makemigrations. 2.python manage.py migrate. delete

Also you can follow the most rated comment. But commentate the newly deleted app name from dependencies. Don't commentate the whole dependencies.

Upvotes: 0

Lukasz Dynowski
Lukasz Dynowski

Reputation: 13700

If you have dangling dependency to 0002_auto_20160618_1143 in a file created by makemigrations command and file does not exist then, please remove this reference from that file. Remember to to remove migration from django_migrations table as well. That fixed my issue

dependencies = [
    ('workspace', '0002_auto_20160618_1143'),
    ('datasets', '0001_initial'),
]

Upvotes: 0

Ram Shukla
Ram Shukla

Reputation: 19

Delete the file product.0002_auto_20160618_1143 migration file.
and again run the following commands:

1.python manage.py makemigrations.
2.python manage.py migrate.

Upvotes: 0

Lokraj Ghimire
Lokraj Ghimire

Reputation: 51

If it not solve after reseting the migrations, follow the following steps: Apparently django kept migration files within it's own module folder. This is why you need to flush the django:

  1. pip uninstall django.
  2. /Lib/site-packages, deleted django folder.
  3. Deleted all *.pyc files in my project.
  4. Deleted all pycache folders in my project.
  5. Cleared all migrations folders in my project (keep init.py).
  6. pip install django==x.x.x.
  7. python manage.py migrate.
  8. python manage.py makemigrations <app_name>.
  9. python manage.py migrate.
  10. python manage.py runserver. Now your problem will be solved.

Upvotes: 5

Hamidreza
Hamidreza

Reputation: 1677

If you have not any serious data in your database, you can simply reset your migrations, as it's been explained here.

Upvotes: 4

kylieCatt
kylieCatt

Reputation: 11049

If you open the migration file products.0002_auto_20160618_1143 you will see a section called dependencies:

dependencies = [("products", "0001_initial")]

Which will look like that. This line tell Django that the current file depends on that file. A file that given that error message isn't there. You can try commenting out that line and running the command again. Be aware that if one file is missing it's possible many are missing so you should reconcile your dependencies with what files you actually have.

DISCLAIMER: If this is a production DB messing around with migration files can be dangerous if you don't know what you are doing. You should test this on a staging or dev server first (preferably one that has a snapshot you can restore to).

Upvotes: 27

Related Questions