How to set auto-increment start in Laravel migrations?

Laravel has a great database migration mechanism, but there are some things missing there. For example, what if you want your IDs start with some number, like 140001, 140002 etc?

By default, we have a function increments() to set auto_increment:

Now, there’s no method or function to do something like this:

So we have two options here – both involve interacting with database after we create the initial schema.

Option 1. Raw DB Statement

After Schema::create(), just launch a raw SQL statement to change auto_increment value:

Option 2. Insert and delete record

Another feature of database is that after deleting the record, default auto_increment value still stays the same and continues from the latest number. So you can do this:

So, which method do you prefer? Have you done something like that in your projects?

Update 2018-01-01. Our reader Gabriel Caruso tried to commit a pull request to the core framework for this.

laravel auto_increment start pull request

But Taylor rejected it with short answer “No plans to add right now”.

laravel taylor pull request

Check out my new online course: Creating Invoices with Laravel 5.6