简体   繁体   English

MySQL / phpMyAdmin 在没有发生口是心非的情况下在 UNIQUE 列上抛出口是心非的错误

[英]MySQL / phpMyAdmin throws duplicity error on UNIQUE column when no duplicity occurs

I have the following table:我有下表:

CREATE TABLE pret_user (
    pret_user_index INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    pret_user_fname VARCHAR(250) NOT NULL,
    pret_user_lname VARCHAR(250) NOT NULL,
    pret_user_email VARCHAR(250) NOT NULL,
    pret_user_telegram_subscribe_token_hash VARCHAR(64) UNIQUE,
    pret_user_telegram_subscribe_token_hash_valid_until INT(15),
    pret_user_telegram_chat_id INT(15) UNIQUE,
    pret_user_telegram_subscribed TINYINT(1) NOT NULL DEFAULT 0
);

when I try to manually update a value of pret_user_telegram_chat_id , the following error is shown warning of duplicit value in a UNIQUE column even though there is no value with the same value (the table only has 4 rows so I checked manually).当我尝试手动更新pret_user_telegram_chat_id的值时,即使没有具有相同值的值(该表只有 4 行,所以我手动检查),也会显示以下错误警告 UNIQUE 列中的重复值。 I've also noticed that while I'm trying to set the value to 5163196961 , the warning is about value 2147483647 .我还注意到,当我尝试将值设置为5163196961时,警告是关于值2147483647的。 Any ideas as to what might be causing this would be much appreciated!任何关于可能导致这种情况的想法将不胜感激!

SQL: SQL:

UPDATE `d28748_admin`.`pret_user`
SET    `pret_user_telegram_chat_id` = '5163196931` 
WHERE  `pret_user`.`pret_user_index` = 2

Error:错误:

#1062 - Duplicate entry '2147483647' for key 'pret_user_telegram_chat_id'

错误截图

To get around the problem, I switched the column to VARCHAR for the time being and after that the problem disappeared, but I'd really like to get to the bottom of why this happened in case I have a similar problem in the future.为了解决这个问题,我暂时将列切换为 VARCHAR,之后问题就消失了,但我真的很想弄清楚为什么会发生这种情况,以防将来遇到类似的问题。

Your pret_user_telegram_chat_id is too small.您的 pret_user_telegram_chat_id 太小了。 The max value for INT is 2147483647 , even though you've specified 15 spots. INT 的最大值是 2147483647 ,即使您指定了 15 个点。 You'll want BIGINT instead你会想要 BIGINT

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM