diff --git a/openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/pre-migration.py b/openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/pre-migration.py index 66caaf34e073..b13460d0398e 100644 --- a/openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/pre-migration.py +++ b/openupgrade_scripts/scripts/hr_recruitment/19.0.1.1/pre-migration.py @@ -13,10 +13,20 @@ def hr_candidate2hr_applicant(env): """ openupgrade.merge_models(env.cr, "hr.candidate", "hr.applicant", "candidate_id") openupgrade.rename_tables(env.cr, [("hr_candidate", None)]) - openupgrade.lift_constraints( - env.cr, openupgrade.get_legacy_name("hr_candidate"), "id", cascade=True + legacy_table = openupgrade.get_legacy_name("hr_candidate") + # PostgreSQL >= 17 catalogs NOT NULL as a named constraint and refuses to + # drop it while the column is still part of a primary key, even when the + # pkey drop is queued in the same ALTER TABLE statement (as + # openupgrade.lift_constraints does). Drop the pkey first, on its own, so + # the remaining lift_constraints() call only has the not-null constraint + # left to lift. + env.cr.execute( + "alter table {} drop constraint if exists {} cascade".format( + legacy_table, legacy_table + "_pkey" + ) ) - openupgrade.remove_tables_fks(env.cr, [openupgrade.get_legacy_name("hr_candidate")]) + openupgrade.lift_constraints(env.cr, legacy_table, "id", cascade=True) + openupgrade.remove_tables_fks(env.cr, [legacy_table]) @openupgrade.migrate()