Я пытаюсь выучить отношения в базе данных Room, но у меня есть некоторые проблемы.Я хочу поставить Expense to Date, но приложение аварийно завершает работу, и logcat показывает это: Причина: android.database.sqlite.SQLiteConstraintException: не выполнено ограничение FOREIGN KEY (код 787).Классы вставляются без методов установки и получения.
Дата:
@Entity(tableName = "dates")
public class Date {
@PrimaryKey(autoGenerate = true)
private int id;
private Long dateLong = System.currentTimeMillis();
private String date = new SimpleDateFormat("MM/yyyy").format(new java.util.Date(dateLong));
private int month;
private int week;
private int day;
private int dayOfWeek;
private String weekDay
public Date(int month, int week, int day, int dayOfWeek, String weekDay) {
this.month = month;
this.week = week;
this.day = day;
this.dayOfWeek = dayOfWeek;
this.weekDay = weekDay;
}
Расход:
@Entity(tableName = "expense_table",
foreignKeys = @ForeignKey(entity = com.example.test.Date.class,
parentColumns = "id",
childColumns = "dateId",
onDelete = CASCADE),
indices = @Index("dateId"))
public class Expense {
@PrimaryKey(autoGenerate = true)
private int id;
private int dateId;
private String note;
private Double value;
private String type;
public Expense(Double value, String note, String type) {
this.value = value;
this.note = note;
this.type = type;
}