Laravel 迁移无法创建外键

Laravel migration can't create foreign key

我正在尝试创建一个外键,artisan 没有向我显示任何错误,只是没有创建我的外键,这可能是我的代码:

1°table:

Schema::create('cooperados', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->timestamps();
        $table->string('nameCoop', 255);
        $table->integer('numCoop');
        $table->string('cpfCoop', 11);
        $table->date('dtCad');
        $table->date('dtDem')->nullable();
        $table->text('description')->nullable();
        $table->decimal('subscritas', 6, 2);
        $table->decimal('integralizadas', 6,2)->nullable();
        $table->decimal('aintegralizar', 6,2)->nullable();
        $table->enum('status', ['ativo','inativo'])->default('ativo');
    });

外键table

public function up()
    {
        Schema::create('mov', function (Blueprint $table) {
            $table->bigIncrements('idMov');
            $table->timestamps();
            $table->integer('id_coop')->unsigned;
            $table->foreign('id_coop')->references('id')->on('cooperados');
            $table->decimal('valor', 6, 2);
        });
    }

更改您的代码
$table->integer('id_coop')->unsigned;
$table->foreign('id_coop')->references('id')->on('cooperados');

收件人:

$table->unsignedBigInteger('id_coop')->index();
$table->foreign('id_coop')->references('id')->on('cooperados')->onDelete('cascade');

或者你也可以使用下面的代码

 $table->integer('id_coop')->unsigned()->index();
 $table->foreign('id_coop')->references('id')->on('cooperados')->onDelete('cascade');

或者您也可以使用下面的方法

$table->bigInteger('id_coop')->unsigned()->index();
$table->foreign('id_coop')->references('id')->on('cooperados')->onDelete('cascade');