Skip to content

Conversation

Xavier-Do
Copy link
Contributor

Since postgres 18 the not null on a field is an explicit constraint named tablename_colname_not_null.
When trying to drop all constraint from a model, an error occurs when trying to drop the id primary key not null constraint.

ALTER TABLE "mail_presence" DROP CONSTRAINT IF EXISTS "bus_presence_id_not_null"
ERROR: column "id" is in a primary key

This commit filters the constraints to remove the id not null one.

We may want to make this filter generic on all not null constraint.

@robodoo
Copy link
Contributor

robodoo commented Oct 9, 2025

Pull request status dashboard

@Xavier-Do Xavier-Do requested review from KangOl and nseinlet October 9, 2025 10:19
upgrade-util Outdated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added by mistake I guess

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ho yes

)
""",
[new_table, old_table.replace("_", r"\_") + r"\_%"],
[new_table, '%s_id_not_null' % old_table, old_table.replace("_", r"\_") + r"\_%"],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could check cr._cnx.server_version >= 180000 and ignore only in that case.

Nit: old_table + '_id_not_null'

@KangOl
Copy link
Contributor

KangOl commented Oct 9, 2025

upgradeci retry with always only mail bus

@Xavier-Do Xavier-Do force-pushed the master-fix-postgres-18-xdo branch from 8707c8a to f654b2b Compare October 9, 2025 15:47
Since postgres 18 the not null on a field is an explicit constraint
named tablename_colname_not_null.
When trying to drop all constraint from a model, an error occurs when
trying to drop the id primary key not null constraint.

    ALTER TABLE "mail_presence" DROP CONSTRAINT IF EXISTS "bus_presence_id_not_null"
    ERROR: column "id" is in a primary key

This commit filters the constraints  to remove the id not null one.

We may want to make this filter generic on all not null constraint
@Xavier-Do Xavier-Do force-pushed the master-fix-postgres-18-xdo branch from f654b2b to 4ee367d Compare October 9, 2025 15:48
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

Successfully merging this pull request may close these issues.

4 participants