我在 sqflite 数据库中创建了两个表,如下面的代码。
await database.execute("CREATE TABLE $debtorTABLE ("
"debtorId INTEGER PRIMARY KEY, "
"name TEXT, "
"mobileNumber TEXT "
")");
await database.execute("CREATE TABLE $debtDetailsTable ("
"debtId INTEGER PRIMARY KEY, "
"amount INTEGER, "
"type TEXT, "
"datetime TEXT, "
"comments TEXT, "
"FK_debtorId INTEGER, "
"FOREIGN KEY(FK_debtorId) REFERENCES $debtorTABLE(debtorId)"
")");
并为这两个表创建了模型,
1. 第一张表的模型
class Debtor {
int debtorId;
String name;
String mobileNumber;
Debtor({this.debtorId, this.name, this.mobileNumber});
................
...............
}
2. 第二张桌子的型号
class Debtor {
int debtId ;
String amount;
String type;
String datetime;
String comments;
*//Should i include foreign key here*
Debtor({this.debtId, this.amount, this.type, this.datetime, this.comments });
................
...............
}
问:我应该在第二个模型中包含外键列吗?如果任何数据类型错误,请纠正我。
提前致谢....