Home > other >  Start primary key from a value in Laravel
Start primary key from a value in Laravel

Time:08-19

I need to set the value of my primary key to start from 1150, but I can't lose my DB data, I created a new migration and executed the following codes:

    public function up()
    {
        Schema::table('tickets', function (Blueprint $table) {
            $table->id()->startValue(1150)->change();
        });
    }

I tried to run too

    public function up()
    {
        Schema::table('tickets', function (Blueprint $table) {
            $table->id()->from(1150)->change();
        });
    }

Even running these migrations, the table keeps inserting in the default value of ids, 5, 6, 7...

CodePudding user response:

Schema::table('tickets', function (Blueprint $table) {
   DB::update("ALTER TABLE tickets AUTO_INCREMENT = 1150;");
});
  • Related