I would know if that is possible to create a possible null reference on foreign key with room.
For now my database structure is like this :
@Entity(tableName = "A")
class A {
@PrimaryKey(autoGenerate = true)
public long id;
}
@Entity(tableName = "B")
class B{
@PrimaryKey(autoGenerate = true)
public long id;
}
@Entity(tableName = "C", foreignKeys = {@ForeignKey(entity = A.class, parentColumns = "id", childColumns = "foreign_id_a"), @ForeignKey(entity = B.class, parentColumns = "id", childColumns = "foreign_id_b")})
class C{
public long id;
public long foreign_id_a;
public long foreign_id_b;
}
I would like to be able to insert the following objects :
C(id=1, foreign_id_a=1, foreign_id_b=1)
C(id=1, foreign_id_a=null, foreign_id_b=1)
C(id=1, foreign_id_a=1, foreign_id_b=null)
But the previous insert with null value give this error : FOREIGN KEY constraint failed (Sqlite code 787 SQLITE_CONSTRAINT_FOREIGNKEY)
Is there a way to make it possible ?