【发布时间】:2020-08-24 08:37:09
【问题描述】:
这是迁移
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->timestamps();
我已经尝试过用这行来做到这一点
$table->bigInteger(‘user_id’)->unsigned()->nullable()->default(null);
$table->foreign(‘user_id’)->references(‘id’)->on(‘users’)->onDelete(‘cascade’);
我做了什么
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->integer(‘user_id’)->unsigned()->nullable()->default(null);
$table->foreign(‘user_id’)->references(‘id’)->on(‘users’)-
>onDelete(‘cascade’);
我得到了什么 错误异常进入
使用未定义的常量“user_id” - 假定为“user_id”(这将在 PHP 的未来版本中引发错误)
【问题讨论】:
-
请重新检查使用的报价。也许你使用了错误的字符。它们应该是 " 或 ' (就像您使用
'posts'一样),但不是 `(反引号),也不是像您所拥有的特殊:$table->integer(‘user_id’)
标签: mysql migration database-migration laravel-7