yuweiguocn / GreenDaoUpgradeHelper

To solve database upgrade of greenDao and just need one line code
1.53k stars 295 forks source link

180行执行报错:【Failed to restore data from temp table 】MUSIC_TEMP android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MUSIC._id (code 1555) #29

Closed yuxingfafu closed 6 years ago

yuxingfafu commented 7 years ago

07-12 15:44:32.985 2846-2846/com.jinrisheng.yinyuehui E/MigrationHelper: 【Failed to restore data from temp table 】MUSIC_TEMP android.database.sqlite.SQLiteConstraintException: UNIQUE constraint failed: MUSIC._id (code 1555) at android.database.sqlite.SQLiteConnection.nativeExecuteForChangedRowCount(Native Method) at android.database.sqlite.SQLiteConnection.executeForChangedRowCount(SQLiteConnection.java:732) at android.database.sqlite.SQLiteSession.executeForChangedRowCount(SQLiteSession.java:754) at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:64) at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1676) at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1605) at org.greenrobot.a.d.f.a(StandardDatabase.java:37) at com.jinrisheng.yinyuehui.util.b.b.c(MigrationHelper.java:180)

yuxingfafu commented 7 years ago

~ package com.jinrisheng.yinyuehui.model;

import android.os.Parcel; import android.os.Parcelable;

import org.greenrobot.greendao.annotation.Entity; import org.greenrobot.greendao.annotation.Id; import org.greenrobot.greendao.annotation.Property; import org.greenrobot.greendao.annotation.Unique; import org.greenrobot.greendao.annotation.Generated;

/**

yuweiguocn commented 7 years ago

添加了唯一键约束@unique导致的,把@unique去掉试试。

atearsan commented 6 years ago

@yuweiguocn id如果设置成主键就是不能重复的。 把INSERT INTRO换成INSERT OR REPLACE INTO可以处理重复的问题。 @yuxingfafu

yuweiguocn commented 6 years ago

@atearsan 好的,感谢。