【问题标题】:strange thing about foreign key in laravel关于laravel中外键的奇怪事情
【发布时间】:2019-08-24 20:42:48
【问题描述】:

我在 laravel 中使用外键时遇到奇怪的问题

当我使用 unsignedBigInteger 外键工作

Schema::table('posts', function (Blueprint $table) {
    $table->unsignedBigInteger('user_id');

    $table->foreign('user_id')->references('id')->on('users');
});

但如果我只是将 Datatype 编辑为

$table->*​​unsignedInteger('user_id');

** 或

$table->Integer('user_id');

外键不起作用

我不知道为什么会这样

【问题讨论】:

    标签: php laravel-5


    【解决方案1】:

    如果你想让你的 id 数据类型为 unsignedIntegerInteger 你需要首先将其迁移文件中的用户 id 数据类型更改为相同的数据类型,因为外键必须在两者之间具有相同的数据类型列

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-12-27
      • 1970-01-01
      • 2020-11-18
      • 1970-01-01
      • 2017-07-27
      • 2018-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多