Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 拉威尔:可以';即使使用';外国直接投资';方法_Laravel - Fatal编程技术网

Laravel 拉威尔:可以';即使使用';外国直接投资';方法

Laravel 拉威尔:可以';即使使用';外国直接投资';方法,laravel,Laravel,我将刷新我的迁移。但是php artisan migrate:refresh命令不起作用。 它显示以下错误: [Illumb\Database\QueryException]SQLSTATE[42000]:语法错误 或访问冲突:1091无法删除“类\用户ID \外部”;检查 该列/键存在(SQL:altertableclassesdrop外键 classes\u userid\u foreign) [PDOException]SQLSTATE[42000]:语法错误或访问冲突: 1091不能删除

我将刷新我的迁移。但是
php artisan migrate:refresh
命令不起作用。 它显示以下错误:

[Illumb\Database\QueryException]SQLSTATE[42000]:语法错误 或访问冲突:1091无法删除“类\用户ID \外部”;检查 该列/键存在(SQL:altertable
classes
drop外键
classes\u userid\u foreign

[PDOException]SQLSTATE[42000]:语法错误或访问冲突: 1091不能删除'classes\u userid\u foreign';检查该列/键
存在

我甚至使用了
dropForeign
,但它对我不起作用

我正在显示我的
迁移
文件

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中运行迁移时(无论是向上还是向下),同时发生错误时,事务可能已部分完成,而没有在迁移表中注册它

如果是这种情况,或者您想删除表是否真的存在外键,那么您应该考虑禁用外键检查,例如:

public function down()
{
    Schema::disableForeignKeyConstraints();
    Schema::drop('classes');
    Schema::enableForeignKeyConstraints();
}

您是否检查了表并验证了外键是否存在?