首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从不同的表中制作一列参考2列

从不同的表中制作一列参考2列
EN

Stack Overflow用户
提问于 2018-06-08 22:31:31
回答 1查看 806关注 0票数 1

我正在尝试获取两个表,它们都有名为emailpasswordisBusiness的列,并在一个名为authentication的表中自动更新这些值

认证迁移

代码语言:javascript
复制
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();
    });

误差

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

业务表

代码语言:javascript
复制
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';
    });

消费表

代码语言:javascript
复制
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';
        });

这样做合适吗?通过给每个列分配两个外键?我只是有一个语法错误,还是这甚至不可能这样做。

EN

回答 1

Stack Overflow用户

发布于 2018-06-09 03:40:03

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

代码语言:javascript
复制
    $table->integer('isBusiness')->index()->unsigned();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50769174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档