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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:37:50+00:00 2026-05-11T02:37:50+00:00

I have a small database and have been adding entries through a Rails page.

  • 0

I have a small database and have been adding entries through a Rails page. I ‘destroyed’ one of the entries and now my sequence of IDs are skipping by one. For example, I now have 42 then 44, instead of the obvious: 42, 43, 44.

I was wondering if there was a way to edit the ID number of a new object through the console. I have tried:

record.id = 43 record.save 

and

record = record.new record.attributes = { :id => 43 } 

but both didn’t work. I’m fairly certain there has to be a console method for this, but I can’t seem to find much specific on Google and I probably read the Rails API incorrectly… Would I possibly have to do this through direct SQL in sqlite?

Thanks

  • 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. 2026-05-11T02:37:51+00:00Added an answer on May 11, 2026 at 2:37 am

    Would I possibly have to do this through direct SQL in sqlite?

    Yes.

    The whole point of ActiveRecord is that is abstracts DB functions and just returns collections of data. You shouldn’t be worrying about the ID of a record, that is something specific to the DB. Off the top of my head I can’t think of any reasons to reference the model’s ID.

    If your app depends on having a sequenced number then you should add another field to the model which has this. For instance, if I have a store with products (a Product model) and I give the ID number the DB provides to other vendors. Two weeks later, my boss asks me to have a unique, but similar ID for two variations of products: ’45a’ and ’45b’. Nuts. The ID field should only be used by to the database and ActiveRecord, not you or your users, to identify the record.

    There is a small chance that there might be an obscure method which force sets the ID if the DB allows it, but it is obscure for a reason. Don’t try and find it 🙂

    All that being said, type ruby script/dbconsole to quickly pull up the sqlite interface without having to type your password.

    Also, if you delete the sqlite database that will reset the counter and start at 0. With great power comes great responsibility.

    EDIT

    If I remember correctly Dave Thomas wrote about this somewhere. Perhaps here?

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

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Install sphinx. $ easy_install -U Sphinx May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer Groups that have no members (for the many-many pairing): SELECT… May 12, 2026 at 1:03 am
  • Editorial Team
    Editorial Team added an answer There is no need to declare the field/variable like that.… May 12, 2026 at 1:03 am

Related Questions

I have a class called Book; class Book { public string Name { get;
Well I run a small video website and on the actual video page there
I think I've become quite good at the basics of programming (for a variety
I have a small ruby application I wrote that's an anagram searcher. It's for

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.