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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:55:38+00:00 2026-05-31T03:55:38+00:00

Hi I have a table in my rails app that doesnt have any id

  • 0

Hi I have a table in my rails app that doesnt have any id column or primary key. thats because this table was brought into my rails app from a previous app and the table is prepopulated with data. I now realize that without a integer primary key, rails cannot display edit and show views in the browser. So i ned to add a id column to my database that is a primary key and that autoincrements.

Based on my googling, I came across a few posts about creating primary keys for a table but nothing that was complete.

So Im wondering if someone can give me a hand here. So far what I know is in order to change the table one must write a migration and then run it. The command that needs to be run for adding a id column is as follows:

rails generate migration add_id_to_businesses id:primary_key

However after running this command no new column is added to my database. Im not sure how to proceed.. How do I add a new column to my database?

Would really appreciate a hand…..
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. Editorial Team
    Editorial Team
    2026-05-31T03:55:40+00:00Added an answer on May 31, 2026 at 3:55 am
    rails g migration add_id_to_products id:primary_key
    
          invoke  active_record
          create    db/migrate/20120310085527_add_id_to_products.rb
    

    Migration file should look like –

       # db/migrate/20120310085527_add_id_to_products.rb
       class AddIdToProducts < ActiveRecord::Migration
         def change
            add_column :products, :id, :primary_key
         end
       end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a rails app that requires multi-table inheritance for which I am using
Consider this scenario. We have an internal Rails 2 app that connects to a
Hi I have a rails app which has a table called listings. This table
I'm using dwilkie's foreigner plugin for rails. I have a table creation statement that
I have created a table in my Ruby on Rails application that I am
I have table and this table contain result column with some entries. I just
I have a rails app which is already running with some users, users that
I have a rails app that makes web api call , the rails app
So, I have an app/assets/stylesheets/ directory structure that looks something like this: |-dialogs |-mixins
I have a rails app that references the TMY3 meteorological dataset , which is

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.