tompmstephenson / LazyChef

EECS 393 Group project
0 stars 0 forks source link

Room Database Foreign Key Error #2

Open EdwardSeley opened 5 years ago

EdwardSeley commented 5 years ago

2019-04-12 01:17:01.206 21203-21723/com.example.thomasstephenson.lazychef E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #2 Process: com.example.thomasstephenson.lazychef, PID: 21203 java.lang.RuntimeException: An error occurred while executing doInBackground() at android.os.AsyncTask$3.done(AsyncTask.java:353) at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:383) at java.util.concurrent.FutureTask.setException(FutureTask.java:252) at java.util.concurrent.FutureTask.run(FutureTask.java:271) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:245) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636) at java.lang.Thread.run(Thread.java:764) Caused by: android.database.sqlite.SQLiteConstraintException: FOREIGN KEY constraint failed (code 787) ################################################################# Error Code : 787 (SQLITE_CONSTRAINT_FOEIGNKEY) Caused By : Abort due to constraint violation. (FOREIGN KEY constraint failed (code 787)) ################################################################# at android.database.sqlite.SQLiteConnection.nativeExecuteForLastInsertedRowId(Native Method) at android.database.sqlite.SQLiteConnection.executeForLastInsertedRowId(SQLiteConnection.java:952) at android.database.sqlite.SQLiteSession.executeForLastInsertedRowId(SQLiteSession.java:788) at android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java:86) at android.arch.persistence.db.framework.FrameworkSQLiteStatement.executeInsert(FrameworkSQLiteStatement.java:50) at android.arch.persistence.room.EntityInsertionAdapter.insert(EntityInsertionAdapter.java:64) at com.example.thomasstephenson.lazychef.IngredientDao_Impl.insert(IngredientDao_Impl.java:123) at com.example.thomasstephenson.lazychef.PantryActivity$IngredientsAsync.doInBackground(PantryActivity.java:177) at com.example.thomasstephenson.lazychef.PantryActivity$IngredientsAsync.doInBackground(PantryActivity.java:163) at android.os.AsyncTask$2.call(AsyncTask.java:333) at java.util.concurrent.FutureTask.run(FutureTask.java:266)

tps48 commented 5 years ago

Pretty sure it has something to do with the way we implemented this in IngredientEntity.java:

@Entity(foreignKeys = @ForeignKey(entity = RecipeEntity.class,
                        parentColumns = "id",
                        childColumns = "recipeId",
                        onDelete = CASCADE),
        indices = {@Index("recipeId")})
public class IngredientEntity {

This is the only place where we join on a foreign key. I will continue to look into this.