I want to create an object and assign it an ID manually. For example Model.create(id: 100, title: 'Object 100')

How to make that when creating the next Model.create object (title: 'Object 101'), its ID was respectively 101, and not 1 as reils does?

    1 answer 1

    Here they write that you need to set the auto-increment counter for the table field. That is, auto-increment is not controlled by Rails, but by the DBMS.

    For MySQL you need to run:

     ActiveRecord::Base.connection.execute("ALTER TABLE table_name AUTO_INCREMENT = 100") 

    For Postgres:

     ActiveRecord::Base.connection.execute("ALTER SEQUENCE table_name_id_seq START with 100 RESTART;") 

    You need to generate a migration, put the above code there, replacing table_name with the name of the table, start the migration.