如何修复 "Method Illuminate\Database\Schema\Blueprint::id does not exist"

how to fix "Method Illuminate\Database\Schema\Blueprint::id does not exist"

当我使用 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 版本。 您可以使用 $table->id(); 来自 laravel 7.x 或更高版本

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

$table->bigIncrements('id');