Opened 4 years ago
Closed 4 years ago
#33556 closed Bug (invalid)
Django Error Connecting to Postgres DB on Docker
| Reported by: | Adebayo Osinulu | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 4.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I started a simple Dockerized django app, however, when I tried to connect to the DB (PostgreSQL, also on Docker) I get this error
ERROR: column c.relispartition does not exist at character 54
db_1 | STATEMENT:
db_1 | SELECT c.relname,
db_1 | CASE WHEN c.relispartition THEN 'p' WHEN c.relkind IN ('m', 'v') THEN 'v' ELSE 't' END
db_1 | FROM pg_catalog.pg_class c
db_1 | LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace
db_1 | WHERE c.relkind IN ('f', 'm', 'p', 'r', 'v')
db_1 | AND n.nspname NOT IN ('pg_catalog', 'pg_toast')
db_1 | AND pg_catalog.pg_table_is_visible(c.oid)
db_1 |
web_1 | Exception in thread django-main-thread:
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 83, in _execute
web_1 | return self.cursor.execute(sql)
web_1 | psycopg2.errors.UndefinedColumn: column c.relispartition does not exist
web_1 | LINE 3: CASE WHEN c.relispartition THEN 'p' WHEN c.relki...
web_1 | ^
web_1 |
web_1 |
web_1 | The above exception was the direct cause of the following exception:
web_1 |
web_1 | Traceback (most recent call last):
web_1 | File "/usr/local/lib/python3.8/threading.py", line 932, in _bootstrap_inner
web_1 | self.run()
web_1 | File "/usr/local/lib/python3.8/threading.py", line 870, in run
web_1 | self._target(*self._args, **self._kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
web_1 | fn(*args, **kwargs)
web_1 | File "/usr/local/lib/python3.8/site-packages/channels/management/commands/runserver.py", line 76, in inner_run
web_1 | self.check_migrations()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 505, in check_migrations
web_1 | executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/executor.py", line 18, in __init__
web_1 | self.loader = MigrationLoader(self.connection)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 53, in __init__
web_1 | self.build_graph()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/loader.py", line 223, in build_graph
web_1 | self.applied_migrations = recorder.applied_migrations()
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 77, in applied_migrations
web_1 | if self.has_table():
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/migrations/recorder.py", line 56, in has_table
web_1 | tables = self.connection.introspection.table_names(cursor)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 52, in table_names
web_1 | return get_names(cursor)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/base/introspection.py", line 47, in get_names
web_1 | return sorted(ti.name for ti in self.get_table_list(cursor)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/postgresql/introspection.py", line 49, in get_table_list
web_1 | cursor.execute("""
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 99, in execute
web_1 | return super().execute(sql, params)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 67, in execute
web_1 | return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
web_1 | return executor(sql, params, many, context)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 85, in _execute
web_1 | return self.cursor.execute(sql, params)
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/utils.py", line 90, in __exit__
web_1 | raise dj_exc_value.with_traceback(traceback) from exc_value
web_1 | File "/usr/local/lib/python3.8/site-packages/django/db/backends/utils.py", line 83, in _execute
web_1 | return self.cursor.execute(sql)
web_1 | django.db.utils.ProgrammingError: column c.relispartition does not exist
web_1 | LINE 3: CASE WHEN c.relispartition THEN 'p' WHEN c.relki...
web_1 | ^
The bug seems to emanate from utils.py in /django/db/backends/
Downgrading Django version to 3.2 provides a temporary fix, upon upgrading to 4.0 issue persist.
Note:
See TracTickets
for help on using tickets.
Django 4.0 dropped support for PostgreSQL 9.6. Django 4.1+ will give a more helpful error message when using an unsupported database version (#33379).