使用外键字符串执行迁移时出错

Error executing migration with foreign key string

我有这两个迁移

tb_store

        Schema::create('tb_store', function (Blueprint $table) {
            $table->integer('cnpj')->unsigned();
            $table->string('email', 255);
            $table->string('password', 255);
            $table->string('corporateName', 255);
            $table->primary(['cnpj', 'email']);
            $table->timestamps();
            $table->softDeletes();
        });

tb_store_地址

        Schema::create('tb_store_address', function (Blueprint $table) {
            $table->string('email', 255);
            $table->foreign('email')->references('email')->on('tb_store')->cascadeOnDelete();
            $table->integer('cnpj')->unsigned();
            $table->foreign('cnpj')->references('cnpj')->on('tb_store')->cascadeOnDelete();
            $table->primary(['cnpj', 'email']);
            $table->string('address', 255);
            $table->integer('number')->unsigned();
            $table->integer('phone')->unsigned();
            $table->integer('postalCode')->unsigned();
            $table->string('neighborhood', 255);
            $table->string('complement', 255)->nullable();
            $table->integer('idCity')->unsigned();
            $table->foreign('idCity')->references('idCity')->on('tb_city')->cascadeOnDelete();
        });

当我 运行 我得到以下错误

https://laravel.com/docs/8.x/migrations#creating-indexes

最简单的方法是链接唯一函数。

    Schema::create('tb_store', function (Blueprint $table) {
        $table->integer('cnpj')->unsigned()->unique();
        $table->string('email', 255)->unique();
        $table->string('password', 255);
        $table->string('corporateName', 255);
        $table->primary(['cnpj', 'email']);
        $table->timestamps();
        $table->softDeletes();
    });