Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django migration relation does not exist

So I'm trying to run the initial migrations on a django app and when I try to run the migrate command (python manage.py migrate or makemigrations) I get the following error:

psycopg2.ProgrammingError: relation "dotworks_server_internship" does not exist
LINE 1: ...s", "dotworks_server_internship"."questions" FROM "dotworks_...
                                                             ^

I'm on a Windows environment using Django 1.9.6 and my database is postgres. Plus, I'm using PGAdmin to manage my database.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'dotworks',
        'USER': 'postgres',
        'PASSWORD': 'mypasswordgoeshere',
        'HOST': 'localhost',
        'PORT': '5432',
    }
}
like image 940
Miguel Machado Avatar asked Nov 11 '16 13:11

Miguel Machado


1 Answers

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.

like image 104
bandakoo Avatar answered Oct 08 '22 03:10

bandakoo