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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:11:19+00:00 2026-06-10T07:11:19+00:00

For example i have this model: class Product < ActiveRecord::Base attr_accessible :name, :order end

  • 0

For example i have this model:

class Product < ActiveRecord::Base
  attr_accessible :name, :order
end

Then when i did rake db:migrate it created this db/migrate/20120825132038_create_products.rb:

class CreateProducts < ActiveRecord::Migration
  def change
    create_table :products do |t|
      t.integer :order
      t.string :name

      t.timestamps
    end
  end
end

But it all happend cuz i used rails generate Product order:integer name:string

Now after i go to Product model and changes it manually to:

class Product < ActiveRecord::Base
  attr_accessible :name, :order, :category_id

  validates :name, uniqueness: true
  belongs_to :category
end

How can i auto update the db/migrate/20120825132038_create_products.rb with the updates?

  • 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-10T07:11:21+00:00Added an answer on June 10, 2026 at 7:11 am

    When you ran rake db:migrate, it did not create db/migrate/20120825132038_create_products.rb. That migration file was created when you ran

    rails generate Product order:integer name:string
    

    attr_accessible has nothing to do with migrating your database.

    I strongly recommend you read the Rails Guide on Migrations, as well as the section on Mass Assignment which discusses attr_accessible.

    To generate a new migration file (since the one mentioned in your Question has already been processed by the previous rake db:migrate command you mentioned running), run

    rails g migration AddCategoryIdToProduct category_id:integer
    

    This should generate a new migration with contents like

    class AddCategoryIdToProduct < ActiveRecord::Migration
      def change
        add_column :products, :category_id, :integer
      end
    end
    

    Running rake db:migrate again now will process this migration file, adding the new category_id integer column to your products table.

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

Sidebar

Related Questions

I have the following models: class Price < ActiveRecord::Base belongs_to :product end class Metric
I have the following model associations: class Product < ActiveRecord::Base has_many :prices class Price
I have a model which uses acts-as-tree. For example: class CartoonCharacter < ActiveRecord::Base acts_as_tree
I have two models. order and line_item. class Order < ActiveRecord::Base has_many :line_items has_many
My models look like this: class Category(models.Model): name = models.CharField(_('name'), max_length=50) class Product(models.Model): name
I have this example: public class Inheritance { public static class Animal { public
I have a model called Vote and this is what vote.rb looks like: class
I have For Example Product and a ProductDetail Table. Where in Model Product is
I have a the following models: class Release < ActiveRecord::Base has_many :products, :dependent =>
I have this models: class Comment(models.Model): text = models.TextField(max_length = 300) author = models.ForeignKey(User)

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.