ActiveAndroid icon indicating copy to clipboard operation
ActiveAndroid copied to clipboard

Column.ConflictAction.REPLACE still causes Foreign Key violation.

Open hdavidzhu opened this issue 9 years ago • 3 comments

Following the example from this guide I have set up the following:

@Column(name = "remote_id", unique = true, onUniqueConflict = Column.ConflictAction.REPLACE)
private int remoteId;

My intentional behavior is for old objects to get overwritten / REPLACEd when updated versions come in from the server. Whenever I try to save a newer version, I get foreign key violation errors.

android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787)
at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method)

hdavidzhu avatar Feb 05 '16 12:02 hdavidzhu

+1

rodrigoGA avatar Feb 09 '17 17:02 rodrigoGA

Have you found a fix or workaround for this?

evanradcliffe avatar Apr 24 '17 20:04 evanradcliffe

what is with this bug? :)

warkaround: User user = new Select().from(User.class).where("userId = ?", userIdYouWantToRetrieve).executeSingle(); if (user != null){ user.setVerified(true); } else { user = new User(){//populate your new user here from json } } user.save();

Tomis1 avatar May 24 '17 09:05 Tomis1