use Illuminate\Support\Facades\Schema;
$foreignKeys = Schema::connection('orders_import')->getForeignKeys('mymuesli_label');
$foreignKeyExists = false;
foreach ($foreignKeys as $foreignKey) {
if ($foreignKey['name'] === 'roll_id') {
$foreignKeyExists = true;
break;
}
}
if (!$foreignKeyExists) {
Schema::connection('orders_import')->table('mymuesli_label', function (Blueprint $table) {
$table->foreign(['roll'], 'roll_id')->references(['id'])->on('mymuesli_roll');
});
}
// Then set the $foreignKeyExists to false and keep with the search on your tables.
(字符串)和 name 的数组数组 columns ,您需要通过迁移来正确获取它 ->foreign($columns, $name) .