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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:35:29+00:00 2026-06-12T12:35:29+00:00

My rails version is 3.2.8 and use the default database. This is my migration

  • 0

My rails version is 3.2.8 and use the default database.
This is my migration code:

class AddQuantityToLineItem < ActiveRecord::Migration
  def change
    add_column :line_items, :quantity, :integer,:default=>1
  end
end

I find a explaination about :default option here and as it said,when i create a
new LineItem ,it should have a default quantity=1,but here is what i get from rails console:

lineb=LineItem.new
#<LineItem id: nil, product_id: nil, cart_id: nil, created_at: nil, updated_at: nil, quantity: nil>

And when i get LineItem from the database,the quantity field is nil
too.

And here is the db/schema.rb :

ActiveRecord::Schema.define(:version => 20121008065102) do

  create_table "carts", :force => true do |t|
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
  end

  create_table "line_items", :force => true do |t|
    t.integer  "product_id"
    t.integer  "cart_id"
    t.datetime "created_at", :null => false
    t.datetime "updated_at", :null => false
    t.integer  "quantity"
  end

  create_table "products", :force => true do |t|
    t.string   "title"
    t.text     "description"
    t.string   "image_url"
    t.decimal  "price",       :precision => 8, :scale => 2
    t.datetime "created_at",                                :null => false
    t.datetime "updated_at",                                :null => false
  end

end
  • 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-12T12:35:30+00:00Added an answer on June 12, 2026 at 12:35 pm

    Your migration should work fine. Based on your schema though it looks like it hasn’t actually taken effect, since t.integer "quantity" has no default value.

    The line in the schema for quantity should look like this:

    t.integer  "quantity",   :default => 1
    

    Make sure you have actually run your migration (bundle exec rake db:migrate), and if that doesn’t work then rollback (bundle exec rake db:rollback) and run the migration again (as @surase.prasad suggested).

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

Sidebar

Related Questions

I want to use the last version of rails, in my Gemfile: gem 'rails',
Short and sweet, Is it ok to use (current version) Ruby 1.9.1 with Rails
This is basically a rails 3 version of this question . Short of parsing
I want to change default date format in Rails. Format should be y/m/d .
I'm using sunspot/rails version 2. It's working great, but I can't figure out how
Firstly here is my ruby and rails version with a couple of the important
I am new to rails. My rails version is 2.3.5. I found usage like:
I created sample rails app and deployed into heroku. Rails version is 3.1.3 Ruby
My version is: Rails: 3.2.6 dalli: 2.1.0 My env is: config.action_controller.perform_caching = true config.cache_store
I have installed two different version of rails in same gem set. When I

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.