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

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

报告相同问题?

悬赏问题

  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化