-
Notifications
You must be signed in to change notification settings - Fork 23
Description
In the same vein as a couple of the other issues, I'm encountering a runtime error when attempting to open my database for the first time. However, my issue is that despite my own SQL-created database and my Room-generated database appearing to perfectly coincide, I get an error saying migration was not properly handled. And the problem is, I have no idea what the difference is because the "Found:" line in the error message is truncated part of the way through. I'm unsure if this is an actual real issue with the database representation being broken, or simply an issue with the error message for some reason.
Here's what I see:
Caused by: java.lang.IllegalStateException: Migration didn't properly handle Assist(<package name>).
Expected:
TableInfo{name='Assist', columns={effect=Column{name='effect', type='TEXT', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', notNull=true, primaryKeyPosition=1}, dance=Column{name='dance', type='INTEGER', notNull=true, primaryKeyPosition=0}, heal=Column{name='heal', type='INTEGER', notNull=true, primaryKeyPosition=0}, name=Column{name='name', type='TEXT', notNull=true, primaryKeyPosition=0}, range=Column{name='range', type='INTEGER', notNull=true, primaryKeyPosition=0}, predecessor=Column{name='predecessor', type='TEXT', notNull=false, primaryKeyPosition=0}, sp_cost=Column{name='sp_cost', type='INTEGER', notNull=true, primaryKeyPosition=0}}, foreignKeys=[ForeignKey{referenceTable='Assist', onDelete='NO ACTION', onUpdate='NO ACTION', columnNames=[predecessor], referenceColumnNames=[name]}], indices=[Index{name='index_Assist_predecessor', unique=false, columns=[predecessor]}, Index{name='index_Assist_name', unique=true, columns=[name]}]}
Found:
TableInfo{name='Assist', columns={effect=Column{name='effect', type='TEXT', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', notNull=true, primaryKeyPosition=1}, dance=Column{name='dance', type='INTEGER', notNull=true, primaryKeyPosition=0}, heal=Column{name='heal', type='INTEGER', notNull=true, primaryKeyPosition=0}, name=Column{name='name', type='TEXT', notNull=true, primaryKeyPositio
Any ideas?
For reference, the relevant portion of my SQL database generation:
CREATE TABLE 'Assist' (
'id' INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
'name' TEXT NOT NULL UNIQUE,
'range' INTEGER NOT NULL DEFAULT 1,
'effect' TEXT NOT NULL,
'sp_cost' INTEGER NOT NULL,
'heal' INTEGER NOT NULL DEFAULT 0,
'dance' INTEGER NOT NULL DEFAULT 0,
'predecessor' TEXT NULL,
-- Foreign Keys
FOREIGN KEY (predecessor) REFERENCES 'Assist' ('name')
);
and my Room entity class:
@Entity ( indices = { @Index(value = "name", unique = true),
@Index(value = "predecessor")},
foreignKeys = @ForeignKey( entity = Assist.class,
parentColumns = "name",
childColumns = "predecessor"))
public class Assist {
@PrimaryKey (autoGenerate = true)
public int id;
@NonNull
public String name;
public int range;
@NonNull
public String effect;
@ColumnInfo(name = "sp_cost")
public int spCost;
public int heal;
public int dance;
public String predecessor;
}
EDIT -- Running on a different virtual device (Pixel 2 API 26, was running Nexus 6 API 23) gives me the full error message. Here's what it shows now:
Expected:
TableInfo{name='Assist', columns={effect=Column{name='effect', type='TEXT', notNull=true, primaryKeyPosition=0}, name=Column{name='name', type='TEXT', notNull=true, primaryKeyPosition=0}, heal=Column{name='heal', type='INTEGER', notNull=true, primaryKeyPosition=0}, range=Column{name='range', type='INTEGER', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', notNull=true, primaryKeyPosition=1}, sp_cost=Column{name='sp_cost', type='INTEGER', notNull=true, primaryKeyPosition=0}, predecessor=Column{name='predecessor', type='TEXT', notNull=false, primaryKeyPosition=0}, dance=Column{name='dance', type='INTEGER', notNull=true, primaryKeyPosition=0}}, foreignKeys=[ForeignKey{referenceTable='Assist', onDelete='NO ACTION', onUpdate='NO ACTION', columnNames=[predecessor], referenceColumnNames=[name]}], indices=[Index{name='index_Assist_name', unique=true, columns=[name]}, Index{name='index_Assist_predecessor', unique=false, columns=[predecessor]}]}
Found:
TableInfo{name='Assist', columns={effect=Column{name='effect', type='TEXT', notNull=true, primaryKeyPosition=0}, name=Column{name='name', type='TEXT', notNull=true, primaryKeyPosition=0}, heal=Column{name='heal', type='INTEGER', notNull=true, primaryKeyPosition=0}, range=Column{name='range', type='INTEGER', notNull=true, primaryKeyPosition=0}, id=Column{name='id', type='INTEGER', notNull=true, primaryKeyPosition=1}, sp_cost=Column{name='sp_cost', type='INTEGER', notNull=true, primaryKeyPosition=0}, predecessor=Column{name='predecessor', type='TEXT', notNull=false, primaryKeyPosition=0}, dance=Column{name='dance', type='INTEGER', notNull=true, primaryKeyPosition=0}}, foreignKeys=[ForeignKey{referenceTable='Assist', onDelete='NO ACTION', onUpdate='NO ACTION', columnNames=[predecessor], referenceColumnNames=[name]}], indices=[]}
So the difference is in the indices. However, Room needs those indices to work properly. How do I make equivalents via SQL?