Django migration relation does not exist Django migration relation does not exist django django

Django migration relation does not exist


I had this problem and I had to comment out everything in urls.py that referenced views.py, then run makemigrations. Hope this helps.


Make sure that you don't have any class variables in your code that are calling Django manager

For example:

class SomeViewSet(viewsets.ViewSet):    se = SomeEntity.objects.first()  # fetching some entity on the class level    def list(self, request):    # the rest of the code

So, when you try to create/apply migrations, this variable will also try to initialise, and will try to access SomeEntity, but at that moment that entity doesn't even exist, and the error occurs.


If all other solutions mentioned fail, if you are still in development probably the easiest solution is dropping the database (in pgAdmin 4 2.0, right-click on database) and then run makemigrations and migrate.