[英]How to set the foreign key name in php laravel?
How can I set the name of a foreign key in php laravel
?如何在 php
laravel
中设置外键的名称?
Schema::table('TABLE_NAME', function (Blueprint $table) {
$table->foreign(XXX)
->references(XXX)
->on('REF_TABLE')
->onDelete('cascade');
// HOW TO ACHIEVE SOMETHING LIKE THIS?
//->name('Custom name of foreign key.')
//->comment('Custom comment for foreign key.')
});
You can specify a custom name by filling the second foreign param:您可以通过填写第二个外部参数来指定自定义名称:
->foreign('XXX', 'my_custom_name')
when you build your foreign key column, you can build it like:当您构建外键列时,您可以像这样构建它:
$table->UnsignedBigInteger('xxx')->comment("comment for this column");
you can also find the details in Laravel column-modifiers .您还可以在 Laravel column-modifiers中找到详细信息。
You can make the foreign key in the following way:-您可以通过以下方式制作外键:-
$table->unsignedInteger('XXXX')
->nullable();
$table->foreign('XXXX')
->references('id')
->on('REF_TABLE')
->onDelete('cascade');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.