[Fixed]-How to resolve the "psycopg2.errors.UndefinedTable: relation "auth_user" does not exist" when running django unittests on Travis



I ran into the same problem after adding a model for an app that was already installed, but forgetting to creating the initial migration. OP hid the answer in the comments so here are explicit steps:

$ mkdir myapp/migrations
$ touch myapp/migrations/__init__.py

After this I got a new error when trying to run python manage.py test

psycopg2.errors.InvalidCursorName: cursor "_django_curs_140073820227328_58" does not exist

One more step was needed:

$ python manage.py makemigrations

And then tests ran fine.

๐Ÿ‘คTom McCarty


I deleted the sqllite3 database
then I ran

$ python manage.py migrate 


$ python manage.py migrate --run-syncdb


The issue is that one of your apps is calling or referencing a non-existent model. The model may be in your code but no migration has been run for it.

Fix: Make sure all your apps have a migration package (i.e. migration folder with init.py file), then run makemigrations and migrate.


Leave a comment