Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4172166
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T00:31:49+00:00 2026-05-21T00:31:49+00:00

I have a project hosted on Heroku and would like to change a table’s

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T00:31:49+00:00Added an answer on May 21, 2026 at 12:31 am

    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:

    ActiveRecord::Base.class_eval do
      def self.reset_autoincrement(options={})
        options[:to] ||= 1
        case self.connection.adapter_name
          when 'MySQL'
            self.connection.execute "ALTER TABLE #{self.table_name} AUTO_INCREMENT=#{options[:to]}"
          when 'PostgreSQL'
            self.connection.execute "ALTER SEQUENCE #{self.table_name}_id_seq RESTART WITH #{options[:to]};"
          when 'SQLite'
            self.connection.execute "UPDATE sqlite_sequence SET seq=#{options[:to]} WHERE name='#{self.table_name}';"
          else
        end
      end
    end
    

    Then just run the following as part of a task or right in the console:

    Mytable.reset_autoincrement(:to => 1000)
    

    Make sure to check this handy answer as to why the sqlite may not be working.

    SQLite Reset Primary Key Field

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project hosted on GitHub and I would like to work locally
I have a project hosted at code.google.com. I would like to get the history
I have two different .Net projects, hosted on github. I would like to create
I have a project hosted on git.debian.org (alioth) and I'd like to configure a
I have a Django project hosted on Heroku with a buildpack forked from cirlabs/heroku-buildpack-geodjango
I'm working in a project that is being hosted in appharbor (like heroku for
I'm working on a project that is hosted on Bitbucket. I would also like
I have a project hosted with git. I just recently had to reinstall ubuntu,
I have a Python Facebook project hosted on Google App Engine and use the
I have a private project, and i want it hosted on google code. this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.