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 7066129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:02:51+00:00 2026-05-28T05:02:51+00:00

In my migration I have: def up MyModel.destroy_all MyModel.create!({:id=>1,:name=>’foo’}) MyModel.create!({:id=>2,:name=>’fooBar’}) MyModel.create!({:id=>3,:name=>’fooNull’}) end because I

  • 0

In my migration I have:

def up
   MyModel.destroy_all
   MyModel.create!({:id=>1,:name=>'foo'})
   MyModel.create!({:id=>2,:name=>'fooBar'})
   MyModel.create!({:id=>3,:name=>'fooNull'})
end

because I need to override data that was already on my_models table

But Even though I’m specifying the id on MySQL it continues the numbering from the position it already was.

I need to rest the counter on the auto increment for id to have only this 3 new records with that id values trough Active Record migration on my Ruby on Rails application.

  • 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-28T05:02:52+00:00Added an answer on May 28, 2026 at 5:02 am

    You have 2 separate issues. One is that you are trying to specify the id with mass assignment, rails won’t allow you to do that. See Overriding id on create in ActiveRecord for a way to do that.

    The other issue is that the auto-increment isn’t resetting. Each DBMS has a unique way of setting an increment counter, and rails doesn’t give you a generic way to access them, although it is implemented for some of them (not MySQL), see Rails way to reset seed on id field

    So you’ll need to run the MySQL specific SQL for this, which is something like:

    ALTER TABLE my_models AUTO_INCREMENT = 1;
    

    This should reset to the number after the largest id in your table (1 if there aren’t any)

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

Sidebar

Related Questions

I have the following Rails model: class CreateFoo < ActiveRecord::Migration def self.up create_table :foo
I have a simple database table called Entries: class CreateEntries < ActiveRecord::Migration def self.up
I have a migration that runs an SQL script to create a new Postgres
i have this crazy label for each time i create a migration that use
I have the following migration: def self.up add_column :project_statuses, :system_sequence, :integer, :default => 0,
i have a rails migration: >> cat db/migrate/20091126031039_create_cards.rb class CreateCards < ActiveRecord::Migration def self.up
I have created a new migration: class AddSignatureToUser < ActiveRecord::Migration def self.up add_column :users,
For example I have the following migration class AddStatusField < ActiveRecord::Migration def self.up add_column
I have a migration: def change create_table :tasks do |t| t.date :date, :null =>
I have a migration that will dynamically create tables on fly per date. Something

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.