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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:15:43+00:00 2026-05-27T08:15:43+00:00

This is my first rails app, one I’m creating for the sole purpose of

  • 0

This is my first rails app, one I’m creating for the sole purpose of learning rails.

I created an app where I have Users and Products (and sessions, but this is not relevant here). After doing a rake db:mograte creating a few items and testing, I then wanted to add a relationship, where products belongs_to :users and a users has_many :products.

But of course, since I have already created the tables, there isn’t any column there to save this information.

How do I make a migration on the database so it will reflect this model? Is there a console tool for it? Do I have to install a third party gem?

  • 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-27T08:15:44+00:00Added an answer on May 27, 2026 at 8:15 am

    You can generally add columns right from the command line. Here is an example that might be relevant to your situation:

    In the terminal, navigate to your Rails app and type:

    rails generate migration add_user_id_to_products user_id:integer
    

    This will create a migration automatically that has the user_id column in the products table. You can then migrate the database again to add the latest changes:

    rake db:migrate
    

    You should then have the minimum required for your has_many/belongs_to relationship.

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

Sidebar

Related Questions

I have 4 related migrations in my Rails app: First 3 migrations create one
Hey guys. I'm creating a rails app and being one of the first times
First as a note I am using this plugin in a Rails app. Ok
Saw this piece of code in a Ruby on Rails book. This first one
I did this: [User.first, User.last].to_xml and got this: <users type=array> <user> <created-at type=datetime>2010-03-16T06:40:51Z</created-at> <id
I've been trying to build my first rails app and have gotten stuck on
I have this relationship in a Rails app class Folder has_many :elements end class
I have a rails app which requires users to verify that they own a
Edit: Well maybe this can give a clue. When created a Rails app in
I created a new model in my rails app. Since it's a one-to-one relation

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.