我有两张桌子
settings
和
invoices
.
在我的
设置
表中的列名为
amount
在我放置整数值(它总是会被填充)的地方,然后在我的
发票
表中的列也命名为
数量
值应该从哪里来
设置
桌子
数量
列。
众所周知,关系列通常
id (primary key)
因此,问题是:
如果我在迁移文件中建立了这样的关系,它是否有效(正确)?
Schema::create('invoices', function (Blueprint $table) {
$table->id();
$table->bigInteger('amount');
$table->timestamps();
});
Schema::table('invoices', function (Blueprint $table) {
$table->foreign('amount')->references('amount')->on('settings');
});
我试图与…建立关系的原因
数量
列而不是
id
列是我希望此列始终根据设置量列填充,并避免额外的功能。
捕获
我的设置表总是只包含一行,所以实际上不可能从中提取多行或多个金额列。
你有什么想法(建议)?