我已经在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 });
................
...............
}
问:我应该在第二个模型中包括外键列吗?如果任何数据类型错误,也请纠正我。
提前谢谢。...
答案 0 :(得分:0)
是的
您应该在第二个表中将外币债务人ID包括在内。
如果您不知道哪个债务属于哪个债务人?