gpt4 book ai didi

php - 从单独的表 laravel 中引用 2 列的列

转载 作者:行者123 更新时间:2023-11-30 21:42:56 25 4
gpt4 key购买 nike

我正在尝试获取 2 个表,它们都有名为 email passwordisBusiness 的列,并在一个名为的表中自动更新这些值身份验证

身份验证迁移

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 个外键?我只是有语法错误,还是根本不可能这样做。

最佳答案

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

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

关于php - 从单独的表 laravel 中引用 2 列的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50769174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com