pytest-django icon indicating copy to clipboard operation
pytest-django copied to clipboard

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

Open titovanton opened this issue 3 years ago • 6 comments

Hello! I got the following, when I run pytest:

pytest==6.2.5
pytest-cov==3.0.0
pytest-django==4.5.2
pytest-forked==1.4.0
pytest-xdist==2.5.0
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:85: in _execute
    return self.cursor.execute(sql, params)
E   psycopg2.errors.UndefinedTable: relation "applable_modelname" does not exist

The above exception was the direct cause of the following exception:
/usr/local/lib/python3.10/site-packages/pytest_django/fixtures.py:122: in django_db_setup
    db_cfg = setup_databases(
/usr/local/lib/python3.10/site-packages/django/test/utils.py:208: in setup_databases
    connection.creation.create_test_db(
/usr/local/lib/python3.10/site-packages/django/db/backends/base/creation.py:74: in create_test_db
    call_command(
/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py:187: in call_command
    return command.execute(*args, **defaults)
/usr/local/lib/python3.10/site-packages/django/core/management/base.py:417: in execute
    output = self.handle(*args, **options)
/usr/local/lib/python3.10/site-packages/django/core/management/base.py:90: in wrapped
    res = handle_func(*args, **kwargs)
/usr/local/lib/python3.10/site-packages/django/core/management/commands/migrate.py:223: in handle
    self.sync_apps(connection, executor.loader.unmigrated_apps)
/usr/local/lib/python3.10/site-packages/django/core/management/commands/migrate.py:346: in sync_apps
    with connection.schema_editor() as editor:
/usr/local/lib/python3.10/site-packages/django/db/backends/base/schema.py:124: in __exit__
    self.execute(sql)
/usr/local/lib/python3.10/site-packages/django/db/backends/base/schema.py:151: in execute
    cursor.execute(sql, params)
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:67: in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:76: in _execute_with_wrappers
    return executor(sql, params, many, context)
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:80: in _execute
    with self.db.wrap_database_errors:
/usr/local/lib/python3.10/site-packages/django/db/utils.py:90: in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
/usr/local/lib/python3.10/site-packages/django/db/backends/utils.py:85: in _execute
    return self.cursor.execute(sql, params)
E   django.db.utils.ProgrammingError: relation "applable_modelname" does not exist

applable_modelname - that's for example ofcz :)

That happens when I call pytest. When I specify --reuse-db --nomigrations - tests are passed. That makes me think, that the issue is not in my migrations. What do I do wrong and how to fix it? Thanks!

titovanton avatar Jan 07 '22 00:01 titovanton

I'm suddenly facing this issue as well, did you ever find a solution @titovanton ?

SHxKM avatar Apr 22 '23 12:04 SHxKM

I'm suddenly facing this issue as well, did you ever find a solution @titovanton ?

nope

titovanton avatar May 20 '23 22:05 titovanton

Hi there, I'm also facing a similar issue. Would be great if a workaround ( if any ) for this issue could be shared here.

AnonSar avatar Aug 25 '23 05:08 AnonSar

@AnonSar @titovanton @SHxKM Could it be that this issue is due to having multiple test database configs? I had the same problem when trying to run test with these test settings:

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql",
        ...
    },
    'sqlite': {
        'ENGINE': 'django.db.backends.sqlite3'
    }
}

Removing the sqlite config fixed the issue and let me run pytest without the --no-migrations flag.

Actionb avatar Sep 06 '23 08:09 Actionb