从单独的表中引用2列

h9vpoimq  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(305)

我尝试取两个表,它们都有名为
email password 以及 isBusiness 并在一个名为 authentication 身份验证迁移

Schema::create('authentication', function (Blueprint $table) {
        $table->increments('auth_id');
        $table->string('email');
        $table->foreign('email')->references('email')->on('businesses');
        $table->foreign('email')->references('email')->on('consumers');
        $table->string('password');
        $table->foreign('password')->references('password')->on('businesses');
        $table->foreign('password')->references('password')->on('consumers');
        $table->integer('isBusiness');
        $table->foreign('isBusiness')->references('isBusiness')->on('businesses');
        $table->foreign('isBusiness')->references('isBusiness')->on('consumers');
        $table->timestamps();
    });

错误

SQLSTATE[HY000]: General error: 1005 Can't create table `sprout_db`.`#sql-2
  7a4_30` (errno: 150 "Foreign key constraint is incorrectly formed")

商务桌

Schema::create('businesses', function (Blueprint $table) {
        $table->increments('bus_id', 11);
        $table->string('bus_name', 50);
        $table->string('bus_address', 50);
        $table->string('bus_city', 50);
        $table->string('bus_prov', 50);
        $table->string('bus_postal', 50);
        $table->string('bus_phone', 50);
        $table->string('email', 50);
        $table->string('password', 100);
        $table->integer('isBusiness')->default('1');
        $table->timestamps();
        $table->rememberToken();
        $table->engine = 'InnoDB';
    });

消费者表

Schema::create('consumers', function (Blueprint $table) {
            $table->increments('con_id', 11);
            $table->string('con_fname', 50);
            $table->string('con_lname', 50);
            $table->string('email', 50);
            $table->string('password', 100);
            $table->integer('isBusiness')->default('0');
            $table->timestamps();
            $table->rememberToken();
            $table->engine = 'InnoDB';
        });

这样做对吗?为每列分配2个外键?我只是有一个语法错误,或者这甚至不可能这样做。

5lhxktic

5lhxktic1#

只需将index()方法添加到键中。

$table->integer('isBusiness')->index()->unsigned();

相关问题