我想创建一个迁移,它将删除一个表。我创建了如下迁移:
Schema::table('devices', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('client_id')->nullable();
$table->foreign('client_id')->references('id')->on('clients')->onDelete('cascade');
});
现在我试着像这样把它放下:
Schema::table('devices', function (Blueprint $table) {
$table->dropForeign('devices_client_id_foreign');
$table->drop('devices');
});
但我得到以下错误:
In Connection.php line 664:
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'devices_client_id_foreign'; check that column/key exists (SQL:
更改表格 devices
删除外键 devices_client_id_foreign
)
In PDOStatement.php line 144:
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'devices_client_id_foreign'; check that column/key exists
In PDOStatement.php line 142:
SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'devices_client_id_foreign'; check that column/key exists
4条答案
按热度按时间zfciruhq1#
只需放下整张table(文档):
xmq68pz92#
你可以用这个答案。https://stackoverflow.com/a/30177480/8513937
将列名作为数组传递给dropforeign。在内部,laravel丢弃相关的外键。
cczfrluj3#
试着这样。。。
z4bn682m4#
您只需在删除表之前禁用外键检查,然后再次启用它们,如下所示: