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

  • Home
  • SEARCH
  • 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 8712535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:07:47+00:00 2026-06-13T05:07:47+00:00

In a Rails application, how can I migrate the changes I make in models?

  • 0

In a Rails application, how can I migrate the changes I make in models?

For instance, I know that if I create a model with command rails g model Person name:string, a migration will be created as well. However, if after this step I go to the created model Person and add a new attribute, will this new attribute be automatically added to a migration for later persistance in database?

Or am I looking at this from the wrong side, and an attribute should be added to a migration, and then added to a model?

  • 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-06-13T05:07:48+00:00Added an answer on June 13, 2026 at 5:07 am

    You can’t really “add” an attribute to a model, you do that by creating the migration file and running it — Rails figures out what attributes a model has based on what columns are in the database. However, you do need to add a line to the model to whitelist the attribute if you want to be able to update it via mass assignment. That’s why you’ll often see a line like this in activerecord models:

    attr_accessible :name
    

    But that’s optional and not essential to adding the attribute.

    To actually add the new attribute to your model, first create a migration with:

    rails g migration AddAddressToPerson address:string
    

    That will create the migration file in the db/migration/ directory. (The form “AddXXXToYYY” and “RemoveXXXFromYYY” are understood by rails to mean “add (or remove) a new column to the model XXX”, see the documentation for details). In this case I’ve added an attribute named address which is a string, but you could change that to whatever you want it to be.

    Then to actually update the database, you need to run the migration with rake:

    rake db:migrate
    

    Finally, if you want to allow mass assignment on that attribute, add the attribute to your list of arguments to attr_accessible:

    attr_accessible :name, :address
    

    That should do it.

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

Sidebar

Related Questions

I'm using Ruby on Rails to make an application where businesses can create accounts
My Rails application makes use of Time.zone so that each user can set their
Trying to make a simple application in rails 3. If I create a team
I need to create one config option for my Rails application. It can be
I have created an application in Rails, I want to create a puccuentas model:
Can we send emails from Rails application using Amazon SES SMTP service where sender's
I am developing a Rails 1.0 application (I can't upgrade, it's a strange situation)
I'm new to Rails and making application where college members (teachers and students) can
I can't access env variables in the Rails console, while in the application they
I am building a Rails application that contains Developer s who have Application s.

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.