如何修复"Method IlluminateDatabaseSchemaBlueprint::id does not exist"



当我使用php-artisan-migrate时,我会收到以下错误消息"方法Illuminate\Database\Schema\Blueprint::id不存在"。有人能帮我吗?

这是我的代码:

<?php
use IlluminateSupportFacadesSchema;
use IlluminateDatabaseSchemaBlueprint;
use IlluminateDatabaseMigrationsMigration;
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版本。你可以使用来自laravel 7.x或更高版本的$table->id();

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

$table->bigIncrements('id');

最新更新