Alter table in migration



How could I alter the primary key (auto incremeent) column in my ‘users’ table to start from the number 1000 for example? I saw that we can use this.alter() in the migration, but I’m not sure how to set the value for the id.


1 Like


Maybe in this way

First create a new migration, indicating on it’s name that will be about alter a table structure

Dont forget to choose the Select Table option

$ adonis make:migration alter_categories
> Choose an action
  Create table
> Select table

Now inside the new migration file write the following code

class AlterCategoriesSchema extends schema
    up() {
       this.raw("ALTER TABLE tableName AUTO_INCREMENT = 1000")

Finally run your migrations in this way

adonis migration:run

and try to insert a new record, and if all was correct, the first id should be 1000