You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
By clicking “Sign up for GitHub”, you agree to our
terms of service
and
privacy statement
. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
逻辑删除报唯一索引冲突异常
如User表有二个字段 user_phone,delete_flag。delete_flag是逻辑删除字段,0代表未删除,1代表删除。user_phone字段有唯一索引。此时有记录{"13712345678",0},后来13712345678用户需要注销账号,于是将此记录逻辑删除记录变为{"13712345678",1},即已删除。后来这个用户又用这个手机注册账号,于是向表里添加记录{"13712345678",0},但是因为user_phone有唯一索引,所以插入记录时报唯一索引冲突。开始解决办法是,将唯一索引变为user_phone+delete_flag的联合唯一索引。于是创建用户成功。此时数据表数据为{"13712345678",1},{"13712345678",0}。但是当这个用户再次注销,将记录{"13712345678",0}更改为{"13712345678",1}时,又报联合唯一索引冲突。
所以终极解决办法是,删除字段的值0代表未删除,然后用删除时的时间戳代表删除。但是我们框架删除字段值是写死的无法实现这个功能。望改善。