Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pkey name overflow happened if table name length is more than 58 symbols #47

Open
nitr0man opened this issue Feb 9, 2024 · 0 comments

Comments

@nitr0man
Copy link

nitr0man commented Feb 9, 2024

when I tried to create tsdb table with name longer than 58 symbols I've got an exception:

...........
  File "/venv/lib/python3.12/site-packages/pgtrigger/migrations.py", line 420, in create_model
    super().create_model(model)
  File "/venv/lib/python3.12/site-packages/timescale/db/backends/postgresql/schema.py", line 131, in create_model
    self._create_hypertable(model, field)
  File "/venv/lib/python3.12/site-packages/timescale/db/backends/postgresql/schema.py", line 95, in _create_hypertable
    self._drop_primary_key(model)
  File "/venv/lib/python3.12/site-packages/timescale/db/backends/postgresql/schema.py", line 85, in _drop_primary_key
    self.execute(sql)
  File "/venv/lib/python3.12/site-packages/pgtrigger/migrations.py", line 404, in execute
    return super().execute(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/django/db/backends/postgresql/schema.py", line 48, in execute
    return super().execute(sql, None)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/django/db/backends/base/schema.py", line 202, in execute
    cursor.execute(sql, params)
  File "/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 79, in execute
    return self._execute_with_wrappers(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 92, in _execute_with_wrappers
    return executor(sql, params, many, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 100, in _execute
    with self.db.wrap_database_errors:
  File "/venv/lib/python3.12/site-packages/django/db/utils.py", line 91, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/venv/lib/python3.12/site-packages/django/db/backends/utils.py", line 103, in _execute
    return self.cursor.execute(sql)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/venv/lib/python3.12/site-packages/psycopg/cursor.py", line 737, in execute
    raise ex.with_traceback(None)
django.db.utils.ProgrammingError: constraint "slm_metrics_optimizer_foo_123456789_123456789_123456789_123c369" of relation "slm_metrics_optimizer_foo_123456789_123456789_123456789_123c369" does not exist

it's happened due to table/field/constraint name length limitation (63 bytes), and actual pkey name in that case is slm_metrics_optimizer_foo_123456789_123456789_123456789_12_pkey

pkey = self.quote_name(f'{db_table}_pkey')
- you should limit table name length to first 58 symbols here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant