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

Updating from old schema hits dependency conflict when migrating from old table #612

Open
truthdoug opened this issue Feb 25, 2025 · 0 comments

Comments

@truthdoug
Copy link

truthdoug commented Feb 25, 2025

I work with @easherma-truth and am looking deeper into how to upgrade. I took the advice from issue #541 that he opened and I've gotten past the issue with the dependency.

I am now running into an issue with the id sequence that PostgreSQL created.

The table, as originally created by django-constance looks like this:

> \d constance_config;
+--------+------------------------+----------------------------------------------------------------+
| Column | Type                   | Modifiers                                                      |
|--------+------------------------+----------------------------------------------------------------|
| id     | integer                |  not null default nextval('constance_config_id_seq'::regclass) |
| key    | character varying(255) |  not null                                                      |
| value  | text                   |                                                                |
+--------+------------------------+----------------------------------------------------------------+
Indexes:
    "constance_config_pkey" PRIMARY KEY, btree (id)
    "constance_config_key_key" UNIQUE CONSTRAINT, btree (key)
    "constance_config_key_baef3136_like" btree (key varchar_pattern_ops)

When I run constance.0002_migrate_from_old_table, I get:

  Applying constance.0002_migrate_from_old_table...Traceback (most recent call last):
  File "/path/to/my/.virtualenvs/snakex/lib/python3.12/site-packages/django/db/backends/utils.py", line 89, in _execute
    return self.cursor.execute(sql, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
psycopg2.errors.DependentObjectsStillExist: cannot drop table constance_config because other objects depend on it
DETAIL:  default value for column id of table constance_config_orig depends on sequence constance_config_id_seq
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

I tried dropping the sequence manually but get basically the same error but in reverse:

cannot drop sequence constance_config_id_seq because other objects depend on it
DETAIL:  default value for column id of table constance_config_orig depends on sequence constance_config_id_seq
default value for column id of table constance_config depends on sequence constance_config_id_seq
HINT:  Use DROP ... CASCADE to drop the dependent objects too.

I've searched these issues for "sequence" and "postgres" but don't see any mention of this problem. The refactor ticket that made the schema change says that its testing involved postgres but I'm curious why I'm having this problem.

Django 4.2
django-constance 4.3.2
PostgreSQL 15.6
Python 3.12.7

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