greendao插入数据UNIQUE constraint failed: PURCHASE_ORDER_TABLE._id (code 1555)
来源:互联网 发布:兵棋推演软件 编辑:程序博客网 时间:2024/06/05 13:31
最近在项目即将上线时遇到这个问题,表面上看来很简单
greendao的数据库表,id字段是唯一的,是因为插入了id重复的数据造成的
但是,我们的业务逻辑是,清空数据库之后,再插入数据,理论上不可能出现重复id
DaoUtils.getDaoSession().getPurchaseOrderTableDao().insertInTx(mPurSkuList);
代码行数定位到这个位置
首先想到的是,可能是数据表没有完全清理干净,但是经过调试后发现是确实是全部清除了
继续调试,发现问题
DaoUtils.getDaoSession().getPurchaseOrderTableDao().insertInTx(mPurSkuList);
mPurSkuList为上图数据,insertInTx方法是greendao批量
这里有十条数据,在插入索引为1的数据时,它的id为null,于是自增,greendao将它的id设为4并且插入到表
继续循环,在插入索引为2的数据时,id为4,但此时数据表已有id为4的数据,所以插入失败
发现原因是批量插入时,list中的数据没有全部重置为null,有些数据有id,有些数据没有id,导致没有id的数据自增时,出现冲突,最终插入失败
阅读全文
0 0
- greendao插入数据UNIQUE constraint failed: PURCHASE_ORDER_TABLE._id (code 1555)
- GreenDao 报错 .sqlite.SQLiteConstraintException: UNIQUE constraint failed: user_profile._id (code 1555
- GreenDao 3.0 出现 UNIQUE constraint failed
- 使用GreenDao出现:unique constraint failed解
- greenDAO 报错: UNIQUE constraint fail(code 1555)的解决方法纪实
- 数据库中插入数据错误 android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
- postgresql插入数据提示:duplicate key value violates unique constraint
- UNIQUE constraint failedの原因
- 使用数据库UNIQUE constraint failed
- net.sqlcipher.database.SQLiteConstraintException: error code 19: UNIQUE constraint failed: xxx
- Greendao 插入数据失败
- Android:android.database.sqlite.SQLiteConstraintException:UNIQUE constraint failed
- android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed异常解决
- GreenDao insert 解决 PRIMARY KEY must be unique (code 19)
- android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- ORA-00001: unique constraint (...) violated并不一定是数据冲突
- 深网
- Hive之 优化篇
- 欢迎使用CSDN-markdown编辑器
- 关于supersocker的数据传输中的问题与解决
- PAT甲级 1043
- greendao插入数据UNIQUE constraint failed: PURCHASE_ORDER_TABLE._id (code 1555)
- VLAN原理解释
- Java基本数据类型の字符型
- hdu 4460 Friend Chains # 最短路的最大值
- 容器 迭代器
- MySQL日期时间函数
- dubbo2.5.3消费dubbox提供的服务报错
- tomcat配置的项目总是出现卡死的现象
- 处理html字符串符合json