Search code examples
laravelpostgresqllaravel-8auto-increment

syntax error for "AUTO_INCREMENT" - Laravel


SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "AUTO_INCREMENT" LINE 1: ALTER TABLE orders AUTO_INCREMENT = 1000; ^ (SQL: ALTER TABLE orders AUTO_INCREMENT = 1000

I want my id column to start from 1000 & being AUTO INCREMENT . Below given is given migrations page. I'm getting the above given error while migrating. I'm using Laravel-8 & Pgsql-13 . Any help to solve this is much appreciated.

Schema::create('orders', function (Blueprint $table) {
                $table->increments('id');
                $table->integer('order_userId')->unsigned();
                $table->foreign('order_userId')->references('id')->on('users');
                $table->float('orderTotal');
                $table->integer('createdBy')->unsigned();
                $table->timestamps();
            });
            DB::update("ALTER TABLE orders AUTO_INCREMENT = 1000;");

Solution

  •    $table->id()->startingValue(1000);
    

    This should do the job . supported from Laravel version 8 and above.