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.)