我有一个accounts
表,其上有FOREIGN KEY
个约束:
TABLE "edits" CONSTRAINT "edits_account_id_fkey1" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
我想放弃这个约束,但每次我尝试执行以下命令时都会这样做:
ALTER TABLE accounts DROP CONSTRAINT edits_account_id_fkey1;
我收到此错误:
ERROR: constraint "edits_account_id_fkey1" of relation "accounts" does not exist
显然存在。我正在使用\d accounts
命令查看它。为什么会这样?
------------- ----------- EDIT
accounts
Indexes:
........
Check constraint:
......
Foreign-key constraints:
"accounts_about_markup_id_fkey" FOREIGN KEY (about_markup_id) REFERENCES markups(id) ON DELETE CASCADE
"accounts_best_vita_id_fkey" FOREIGN KEY (best_vita_id) REFERENCES vitae(id)
"accounts_organization_id_fkey" FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE
Referenced by:
TABLE "account_reports" CONSTRAINT "account_reports_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "actions" CONSTRAINT "actions_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "api_keys" CONSTRAINT "api_keys_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "authorizations" CONSTRAINT "authorizations_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "positions" CONSTRAINT "claims_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "duplicates" CONSTRAINT "duplicates_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
TABLE "old_edits" CONSTRAINT "edits_account_id_fkey" FOREIGN KEY (account_id) REFERENCES accounts(id)
TABLE "edits" CONSTRAINT "edits_account_id_fkey1" FOREIGN KEY (account_id) REFERENCES accounts(id) ON DELETE CASCADE
etc...... etc......
答案 0 :(得分:2)
约束放在表edits
上,但您正在更改表accounts
。将查询中的accounts
更改为edits
,然后就可以了。