Im getting Exception Node Not Found while doing migration.

Hello Guys,

Im just stuck with error while making migrations to my django project.
In my project which is already 50% dveloped i use owner model to represent owner of shop and then i used user model for login and for registration purpose.
So i tried to use user model in my owner model so i could utilise both model effectively with additional fields.
I tried to extend user model in owner model using onetoone field. after doing that i was not able to do migrations so i deleted all migrations files but after that it was start giving this error while doing migrations:-

py manage.py makemigrations
Traceback (most recent call last):
File “manage.py”, line 21, in
main()
File “manage.py”, line 17, in main
execute_from_command_line(sys.argv)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management_init_.py”, line 401, in execute_from_command_line
utility.execute()
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management_init_.py”, line 395, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management\base.py”, line 328, in run_from_argv
self.execute(*args, **cmd_options)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management\base.py”, line 369, in execute
output = self.handle(*args, **options)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management\base.py”, line 83, in wrapped
res = handle_func(*args, **kwargs)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\core\management\commands\makemigrations.py”, line 87, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\loader.py”, line 49, in init
self.build_graph()
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\loader.py”, line 274, in build_graph
raise exc
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\loader.py”, line 248, in build_graph
self.graph.validate_consistency()
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\graph.py”, line 195, in validate_consistency
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\graph.py”, line 195, in
[n.raise_error() for n in self.node_map.values() if isinstance(n, DummyNode)]
File “C:\Users\Mayur\PycharmProjects\StartUp\venv\lib\site-packages\django\db\migrations\graph.py”, line 58, in raise_error
raise NodeNotFoundError(self.error_message, self.key, origin=self.origin)
django.db.migrations.exceptions.NodeNotFoundError: Migration listings.0001_initial dependencies reference nonexistent parent node (‘owners’, ‘0001_initial’)

Here is My Owner Model Code:-

from django.db import models
from django.contrib.auth.models import User

class Owner(models.Model):
user = models.OneToOneField(User,on_delete=models.CASCADE, default=False)
name=models.CharField(max_length=200)
photo=models.ImageField(upload_to=‘photos/%Y/%m/%d/’)
description=models.TextField(blank=True)
phone=models.CharField(max_length=20)
email=models.CharField(max_length=20)

def __str__(self):
    return self.name

I hope i will get working solution on this problem so i can move ahead in my project development.

Your database tracks what migrations have previously been applied. When you delete the migration files, you’re breaking that connection between the files in your application and the database.

You may have some luck by emptying the django_migrations table and trying again. Unfortunately, if there are other migrations that have been previously applied, that may cause problems with other tables. (You can end up with migrations failing because the database changes have already been applied.)

You could try deleting all migration files again, empyting the django_migrations table, and retrying the migrations. That’s going to generate errors, usually of the type “something already exists”. At the top of the output, it’ll tell you which migration was being run. If you specifically run that migration with the --fake parameter, it’ll tell django that that migration was previously run and does not need to be reapplied. Do this enough times and you’ll be back to working.

The easier way is to just drop the database, recreate it, start from scratch, and realize that about the last thing you ever want to do is delete all your migration files…

Ken

2 Likes

you were right --fake with migration solved my problem.