Skip to content

Failure dropping a table and a related constraint, when the constraint is included in the cascading drop of the table #382

@cysp

Description

@cysp

To reproduce, apply these two schema documents in sequence:

CREATE TABLE a (id bigint PRIMARY KEY, b_id bigint);

CREATE TABLE b (id bigint PRIMARY KEY);

ALTER TABLE a ADD CONSTRAINT "a_b_id_fkey" FOREIGN KEY ("b_id") REFERENCES "b" ("id");
CREATE TABLE a (id bigint PRIMARY KEY);

Applying the second schema plans correctly but fails with this output:

Plan: 1 to modify, 1 to drop.

Summary by type:
  tables: 1 to modify, 1 to drop

Tables:
  ~ a
    - b_id (column)
    - a_b_id_fkey (constraint)
  - b

DDL to be executed:
--------------------------------------------------

DROP TABLE IF EXISTS b CASCADE;

ALTER TABLE a DROP CONSTRAINT a_b_id_fkey;

ALTER TABLE a DROP COLUMN b_id;

Do you want to apply these changes? (yes/no): yes

Applying changes...

Executing group 1/1...
  Executing 3 statements in implicit transaction
Error: failed to execute concatenated statements in group 1: ERROR: constraint "a_b_id_fkey" of relation "a" does not exist (SQLSTATE 42704)

(The cascading drop of table b has already dropped constraint a_b_id_fkey by the time that drop is executed.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions