丢弃唯一约束的问题

编程入门 行业动态 更新时间:2024-10-25 10:32:36
本文介绍了丢弃唯一约束的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在PG中:

我制作了一个包含唯一电子邮件的用户表,但后来决定电子邮件不应该是唯一的。我进行了更改以使我的电子邮件字段不唯一(我使用ORM,因此实际上没有发生的确切SQL),但是PG仍然不允许我使用重复的电子邮件地址。

I made a user table that includes unique emails, but later decided that emails should not be unique. I pushed changes to make my email field non-unique (I use an ORM, so I don't actually have the exact SQL that took place), but PG still won't let me use duplicate email addresses.

我检查了索引,它不是唯一的,但是有一个约束条件,使我不能拥有重复的电子邮件地址。但是,我在删除此约束时遇到了麻烦。我在做什么错?

I checked the index and it's not unique, but there's a constraint keeping me from having duplicate email addresses. However I'm having trouble dropping this constraint. What am I doing wrong?

SQL> ALTER TABLE "users" DROP CONSTRAINT "unique_users_email" PGError: ERROR: constraint "unique_users_email" of relation "users" does not exist SQL> UPDATE users SET email = 'test@test' PGError: ERROR: duplicate key value violates unique constraint "unique_users_email" DETAIL: Key (email)=(test@test) already exists.

推荐答案

我敢打赌, unique_users_email实际上是唯一的索引,而不是约束。试试:

I bet that "unique_users_email" is actually the name of a unique index rather than a constraint. Try:

DROP INDEX unique_users_email;

当查看表的 \d 描述时,psql的最新版本应该告诉您唯一索引和唯一约束之间的区别。

Recent versions of psql should tell you the difference between a unique index and a unique constraint when looking at the \d description of a table.

更多推荐

丢弃唯一约束的问题

本文发布于:2023-10-24 19:29:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1524805.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!