Django 1.8 test issue: ProgrammingError: relation "auth_user" does not exist

dabadaba

I recently upgraded Django to 1.8 and set up a new development database for a fresh start. Migrations and dependencies went well, safe the usual errors you get and you end up solving. The app is working locally now just fine.

However, I am getting an error when trying to run tests:

python manage.py test

This is the error I am getting:

django.db.utils.ProgrammingError: relation "auth_user" does not exist

Needless to say, Django's auth module is indeed installed and migrated in the app, so I am not sure what is going on.

Here is the full stacktrace in case you need to peek at it, but it does't say anything even remotely helpful to me to figure out the cause of this error:

Traceback (most recent call last):
  File "C:/Users/dabadaba/PycharmProjects/dogpatchsports_com/mysite/manage_sched_dev.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 354, in execute_from_command_line
    utility.execute()
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 346, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 30, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 394, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 74, in execute
    super(Command, self).execute(*args, **options)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\test.py", line 90, in handle
    failures = test_runner.run_tests(test_labels)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 210, in run_tests
    old_config = self.setup_databases()
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 166, in setup_databases
    **kwargs
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\test\runner.py", line 370, in setup_databases
    serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\base\creation.py", line 368, in create_test_db
    test_flush=not keepdb,
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\__init__.py", line 120, in call_command
    return command.execute(*args, **defaults)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\base.py", line 445, in execute
    output = self.handle(*args, **options)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 179, in handle
    created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\core\management\commands\migrate.py", line 318, in sync_apps
    cursor.execute(statement)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "C:\Users\dabadaba\Envs\django18\lib\site-packages\django\db\backends\utils.py", line 62, in execute
    return self.cursor.execute(sql)
django.db.utils.ProgrammingError: relation "auth_user" does not exist

I can figure out a workaround following this answer which prevents the test task from running migrate, which according to what I have been reading should be the point where the error happens. Odd enough, since when I run migrate everything is fine.

However, I would prefer not to resort to a cheeky workaround and stick to doing things as they are designed. Additionally, this error might be a hint that something else is actually wrong and ought to be fixed.

Some solutions suggest running:

python manage.py migrate auth
python manage.py migrate

But that does nothing since there are no pending migrations in my project.

How can I solve this mysterious issue?

Alasdair

If you have any apps which have foreign keys to auth.User, then make sure that the initial migrations for those apps have a dependency on the auth app:

class Migration(migrations.Migration):

    dependencies = [('auth', '__first__')]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

"django.db.utils.ProgrammingError: relation "auth_user" does not exist" Django V2.0

django 1.7 relation "auth_user" does not exist in migrate but fine in tests

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

Django: relation "auth_user" already exists when executing manage.py test myApp

django application on heroku gives 'Programming error at /admin/login "auth_user" does not exist.' on login

ProgrammingError: relation "django_session" does not exist

ProgrammingError: relation "django_site" does not exist

Django test fails with 'django.db.utils.ProgrammingError: relation "django_content_type" does not exist'

how to update django auth_user with queryset?

Password not saving to auth_user table in Django

Django add field to auth_user

Django Setup: No Such Table auth_user

Python Django - Internal Error ProgrammingError relation does not exist

django.db.utils.ProgrammingError: relation "..." does not exist

django.db.utils.ProgrammingError: relation does not exist with recursive model

Django superuser fixture error - no such table: auth_user

django: User Registration with error: no such table: auth_user

Creating a New Table (Model) and Relating it to auth_user in Django

merge django's auth_user with existing user table

Django testing on separate database giving "OperationalError: no such table: auth_user"

How to add columns to auth_user in django postgresql?

ProgrammingError at / relation "main_post" does not exist

Django - ProgrammingError - column does not exist

django.db.utils.ProgrammingError: relation "django_content_type" does not exist

Django Rest Framework "django.db.utils.ProgrammingError: relation "patient" does not exist"

Django issue: relation "django_site" does not exist

ProgrammingError: relation "django_session" does not exist error after installing Psycopg2

Django psycopg2.ProgrammingError relation does not exist using custom model Manager

django.db.utils.ProgrammingError: Could not load : column "" of relation "" does not exist