Skip to content

PostgreSQL - from() / startingValue does not work #58095

@sandervankasteel

Description

@sandervankasteel

Laravel Version

12.40.2

PHP Version

8.4.15

Database Driver & Version

Postgres 18.1

Description

On Postgres, it appears that the from() / startingValue() calls in a migration file do not appear to do anything.

I have a very simple migration file with following up() method;

        Schema::table('users', function (Blueprint $table) {
            $table->bigIncrements('id')
                ->from(2000)
                ->change();
        });

I do expect something related to alter sequence users_id_seq restart with 2000 as can be seen in;

return 'alter sequence '.$table.'_'.$command->column->name.'_seq restart with '.$value;
to be executed on the database server, however, it does not appear to be executed.

The same happens if you use a Schema::create() call, like this for example;

        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id')
                ->from(100);
        });

Based on the previous ::create() statement, the following queries should be sent to the database server;

array:2 [
  0 => "create table "users" ("id" bigserial not null primary key)"
  1 => "alter sequence users_id_seq restart with 100"
]

Yet the ID autoincrement values still start with 1.

If I execute the query alter sequence users_id_seq restart with 100 or alter sequence users_id_seq restart with 2000, manually through my SQL client, it does work.

Steps To Reproduce

  1. Create a simple migration like;
        Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id')
                ->from(100);
        });
  1. Execute it
  2. Try to insert a row
  3. The primary ID of the table still starts with 1 instead of the expected 100.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions