pytest-dev / pytest-dev/pytest-django
django.db.utils.ProgrammingError: relation "applable_modelname" does not exist
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
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!
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure with pytest, comparing it with the successful --reuse-db --nomigrations run. Start at pytest_django/fixtures.py django_db_setup and Django's migrate/sync_apps path shown in the traceback; done means identifying why the test database lacks the relation and verifying the corrective behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100