I have a project hosted on Heroku and would like to change a table’s autoincrement start value. I’m using SQLite3 locally and Heroku uses PostgreSQL This is what I have in the migration:
class CreateMytable < ActiveRecord::Migration
def self.up
create_table :mytable do |t|
t.text :mytext
end
case ActiveRecord::Base.connection.adapter_name
when 'PostgreSQL'
execute 'ALTER SEQUENCE mytable_id_seq RESTART WITH 1000;'
when 'SQLite'
execute 'update sqlite_sequence set seq = 1000 where name = "mytable";'
else
end
end
def self.down
drop_table :mytable
end
end
Locally the migration runs but SQLite seems to just ignore the change, it works on Heroku though. What am I doing wrong?
Honestly, it doesn’t sound like this belongs in a migration. You could add the following to an initializer to make a handy Base class method to call as part of a task, though:
Then just run the following as part of a task or right in the console:
Make sure to check this handy answer as to why the sqlite may not be working.
SQLite Reset Primary Key Field