我在注册时使用科尼托对用户进行身份验证,一旦用户单击“创建帐户”,就应该将其指向验证屏幕(号码和电子邮件),但我的用户正面临此错误。
duplicate key value violates unique constraint "core_user_phone_number_client_key" DETAIL: Key (phone_number, clientid)=(b9e507949695) already exists.我不太确定这个错误是否只与认知或数据库(Postgres)有关,因为我看不到表上的记录,但是当我试图用相同的拒绝的电子邮件创建一个帐户时,表示用户已经存在,但是何时尝试注册它的假定用户不存在(它太棘手了)
发布于 2021-12-09 21:02:00
这显然是一个PostgreSQL错误,除了键有两个列的部分外,但是数据只显示一个列。
通常导致此错误的原因是,一个事务试图两次插入相同的数据,因此与其本身发生冲突。由于事务回滚,两行都消失了。因此,外部观察者永远无法发现违规的数据,因为它从来不存在于提交(可见)形式中。
发布于 2021-12-10 10:20:34
所以这会解决这个问题
operations = [
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_username_key ON core_user (username);'),
# Make sure we take into account related client's id for unique index, to limit uniqueness
# verification by client profiles set (several clients may have profiles with the same email & phone number)
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_email_client_key '
'ON core_user (email, client_id) WHERE is_active = TRUE;'),
migrations.RunSQL('CREATE UNIQUE INDEX IF NOT EXISTS core_user_phone_number_client_key '
'ON core_user (phone_number, client_id) WHERE is_active = TRUE;')
]https://stackoverflow.com/questions/70294535
复制相似问题