Reputation: 26
In my laravel app database i have set the id field (which is the primary key of the table) to auto increment. Now i on the app have deleted all the inputs from the users i have created which in turn clears the values from my database, but then when i create newer values the id field continues with the increment and the app tries to load the deleted value.
i would like to know a way that i can set auto increment to set newer values to the last a number that follows the last number set by Auto Increment.
Upvotes: 1
Views: 410
Reputation: 7499
When creating migration you could set the auto-increment field
$table->increments('id');
or on the migration for change
Schema::table('table', function (Blueprint $table) {
$table->increments('id')->start_from(1)->change();
});
Upvotes: 0
Reputation: 1030
Execute the folowing command:
ALTER TABLE table_name AUTO_INCREMENT = 1;
It will reset the auto increment counter.
Upvotes: 1