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

21๐Ÿ‘

โœ…

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

4๐Ÿ‘

I deleted the sqllite3 database
then I ran

$ python manage.py migrate 

then

$ python manage.py migrate --run-syncdb
๐Ÿ‘คGenie

2๐Ÿ‘

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.

๐Ÿ‘คFemolak

Leave a comment