【发布时间】:2023-03-09 17:20:01
【问题描述】:
我即将刷新我的迁移。但是php artisan migrate:refresh 命令不起作用。
它显示以下错误:
[Illuminate\Database\QueryException] SQLSTATE[42000]:语法错误 或访问冲突:1091 Can't DROP 'classes_userid_foreign';查看 该列/键存在(SQL:alter table
classesdrop foreign keyclasses_userid_foreign)[PDOException] SQLSTATE[42000]:语法错误或访问冲突: 1091 不能 DROP 'classes_userid_foreign';检查该列/键
存在
我什至使用了dropForeign,但它不适合我。
我正在显示我的 migration 文件
public function up()
{
Schema::create('classes', function (Blueprint $table) {
$table->increments('id');
$table->integer('userId')->unsigned();
$table->string('title');
$table->string('name');
$table->string('code')->unique();
$table->integer('capacity')->unsigned();
$table->integer('tagId')->unsigned();
$table->foreign('userId')->references('id')->on('users');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('classes', function (Blueprint $table) {
$table->dropForeign(['userId']);
});
Schema::drop('classes');
}
如何解决这个问题?
【问题讨论】:
-
你检查表并验证外键是否存在?
标签: laravel