Wednesday, April 13, 2022

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

Issue

When i use php artisan migrate , i get this error message "Method Illuminate\Database\Schema\Blueprint::id does not exist". Can someone help me out?

Here is my code:

<?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');
    }
}

Solution

First of all it Depends on which version of laravel you are using. you can use $table->id(); from laravel 7.x or higher versions

OR

if you are using laravel 6.x or lower version you can use

$table->bigIncrements('id');


Answered By - dvijparekh
Answer Checked By - Cary Denson (PHPFixing Admin)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.