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

The Archive Base Latest Questions

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

Do I need to re-migrate whenever I change the models in Rails? Can someone

  • 0

Do I need to re-migrate whenever I change the models in Rails? Can someone tell me what migration really does? I am reading it and I am somewhat confused with the difference between the stuff inside db/migrate and the stuff inside app/models.

For example, if I add a has_one realtionship inside my model, do I need to re-migrate this? Why?

  • 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-15T21:20:28+00:00Added an answer on May 15, 2026 at 9:20 pm

    If your database changes, use a migration. If you’re just adding methods to your model, no need to have a migration.

    Example:

    We start out and we just have first_name, last_name. We want to store those in the database, so we have a migration that does:

    /app/models/human.rb

    # empty
    

    /db/migrate/xxxxx.rb

    add_column :humans, :first_name, :string
    add_column :humans, :last_name, :string
    

    Then we get married, so we want to track that

    /app/models/human.rb

    belongs_to :spouse
    
    • We need to have a spouse_id field in the database, so we need a migration

    /db/migrate/xxxxx.rb

    add_column :humans, :spouse_id, :integer
    
    • We then have a kid…. In fact, we were all kids at one point, but to keep it simple, we’ll have Humans and Offspring

    /app/models/offspring.rb

    belongs_to :human
    

    /db/migrate/xxxxx.rb

    create_table ... 
    
    • However, no need to add anything to the Human migration, since no tables change here. We do need to add:

    /app/models/human.rb

    has_many :offspring
    
    • If you want to be able to get at, easily, your first born, you’d just add a method to your model. No need for a migration here:

    /app/models/human.rb

    def first_born
      offspring.first
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using: windows 7 rails 3.0 whenever i try to run rake db:migrate.
I need to migrate a large project from StarTeam 5 to Subversion, and I'd
I need to migrate Access databases to SQL Server 2005. Since this needs to
I need to migrate our SharePoint farm to a new domain. Until everything is
I need to migrate data from a Plone-based portal to Liferay. Has anyone some
I need to migrate some C# code to Python. The original code makes use
I am using 64-bit Vista and I need to migrate an access database, in
We're at the start of a project where we need to migrate Vignette CM
I need to manually migrate modified stored procedures from a DEV SQL Server 2005
We are planning to migrate our DB to Oracle.We need to manually check each

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.