Ernesto Pareja
Ernesto Pareja

Reputation: 33

How to reset the autoincrement max value when running migrations in Laravel

I'm new to Laravel and I have this table migration working fine

public function up()
{
    Schema::create('tenants', function (Blueprint $table) {
        $table->integer('tenant_id')->autoIncrement();
        $table->string('name', 45);
        $table->integer('plan_id')->nullable();
        $table->integer('status')->nullable();
    });
}

public function down()
{
    Schema::dropIfExists('tenants');
}

If i run php artisan migrate: fresh the auto increment max value is not set back to 1.

I know how to do it in SQL but I want to use Laravel options.

Thank you

Upvotes: 1

Views: 533

Answers (1)

MOHIN SANDHI
MOHIN SANDHI

Reputation: 11

1)we can use from method to set autoincrement start value
$table->integer('tenant_id')->from(number);
2)this will other method to change autoincrement value 
public function up()
{
    Schema::create('tenants', function (Blueprint $table) {
        $table->integer('tenant_id')->autoIncrement();
        $table->string('name', 45);
        $table->integer('plan_id')->nullable();
        $table->integer('status')->nullable();
    });
    \DB::statement('ALTER TABLE tenants AUTO_INCREMENT = 1000;');
}

Upvotes: 1

Related Questions