drgweamoi473182981 2019-07-04 10:43
浏览 106
已采纳

SQLSTATE [23000]:完整性约束违规:密钥qr_codes_encoded_key_unique的重复条目“B”

I have already visited following question.

#1062 - Duplicate entry '' for key 'unique_id' When Trying to add UNIQUE KEY (MySQL)

I have made an string column 'encoded_key' as unique. I have inserted 'b' in that column at first and then I want to add 'B' in the column. I think 'b' and 'B' are different and unique but it shows following error:

Illuminate\Database\QueryException SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'B' for key 'qr_codes_encoded_key_unique'

Are cases ignored in unique constraint in mysql ?

I am using mysql in laravel application.

Any kind of suggestions are appreciated.

  • 写回答

1条回答 默认 最新

  • dream_high1026 2019-07-04 11:24
    关注

    u need to change or set custom collation to utf8_bin

     $table->string('encoded_key')->unique()->collation('utf8_bin');
    

    you may also specify character with collation

    for example : set utf8 also like this

    $table->string('encoded_key')->unique()->charset('utf8')->collation('utf8_bin');
    

    for more information read this article

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历