删除约束时出现错误消息
每次我想从列中删除约束时,我都会收到错误。我看不出问题所在。我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PostgreSQL 中的主键默认称为
_pkey,因此您可能需要这样的内容:
您可以使用
\ 检查
。psql
中的名称 。 d 表APrimary keys in PostgreSQL are by default called
<table>_pkey
, so you probably want something like this:You can check the names for example in
psql
using\d TableA
.这意味着您选择了错误的约束名称 - 您选择了列名称而不是约束
That means that you choose wrong name of constraint - you choose column name instead of constraint