【问题标题】:how to fix "Method Illuminate\Database\Schema\Blueprint::id does not exist"如何修复“方法 Illuminate\Database\Schema\Blueprint::id 不存在”
【发布时间】:2021-04-12 01:12:58
【问题描述】:

当我使用 php artisan migrate 时,我收到此错误消息 “方法 Illuminate\Database\Schema\Blueprint::id 不存在”。有人可以帮帮我吗?

这是我的代码:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateGalleriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('galleries', function (Blueprint $table) {
            $table->id();
            $table->integer('gallery_folder_id')->index();
            $table->string('image');
            $table->string('image_thumbnail');
            $table->string('dimension');
            $table->integer('added_by')->index();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('galleries');
    }
}

【问题讨论】:

    标签: laravel migration laravel-5.8


    【解决方案1】:

    首先取决于你使用的 laravel 版本。 您可以使用 $table-&gt;id(); 来自 laravel 7.x 或更高版本

    如果你使用的是 laravel 6.x 或更低版本,你可以使用

    $table->bigIncrements('id');
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-21
      • 2021-12-30
      • 2014-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-21
      • 2018-09-24
      相关资源
      最近更新 更多