删除约束时出现错误消息

发布于 2024-12-25 13:43:19 字数 407 浏览 6 评论 0原文

每次我想从列中删除约束时,我都会收到错误。我看不出问题所在。我正在使用 postgres。

所以我创建了一个包含两列的表:

CREATE TABLE TableA(
person_id INT PRIMARY KEY,
lastname CHAR(100)
)

我使用代码

ALTER TABLE TableA DROP CONSTRAINT person_id

从 person_id 中删除约束,但随后出现错误:

Error : ERROR:  constraint "person_id" of relation "tablea" does not exist

问题是什么?

Every time I want to drop a constraint from a column I get an error. I can't see the problem. I am using postgres.

So I have created a table with two columns:

CREATE TABLE TableA(
person_id INT PRIMARY KEY,
lastname CHAR(100)
)

I use the code

ALTER TABLE TableA DROP CONSTRAINT person_id

to DROP the constraint from person_id but then I get an error:

Error : ERROR:  constraint "person_id" of relation "tablea" does not exist

What's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我的影子我的梦 2025-01-01 13:43:19

PostgreSQL 中的主键默认称为 _pkey,因此您可能需要这样的内容:

ALTER TABLE TableA DROP CONSTRAINT TableA_pkey;

您可以使用 \ 检查 psql 中的名称 。 d 表A

Primary keys in PostgreSQL are by default called <table>_pkey, so you probably want something like this:

ALTER TABLE TableA DROP CONSTRAINT TableA_pkey;

You can check the names for example in psql using \d TableA.

没︽人懂的悲伤 2025-01-01 13:43:19

这意味着您选择了错误的约束名称 - 您选择了列名称而不是约束

That means that you choose wrong name of constraint - you choose column name instead of constraint

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文