Change starting id number

前端 未结 6 922
灰色年华
灰色年华 2021-02-05 10:53

I have an \'Account\' model in Rails with its corresponding \'accounts\' table in the database. If I wipe the database and start over, the \'account_id\' field will always star

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 11:31

    For sqlite

    sequences are stored in the table sqlite_sequence (name,seq)

    • Check first if the sequence already exists?

      select name,seq from sqlite_sequence where name = 'accounts'

    if sequence.empty?

    insert into sqlite_sequence(name,seq) values('accounts', 1000);

    else

    update sqlite_sequence set seq = 1000 where name = 'accounts';

提交回复
热议问题