I loaded some seed data in using the code below, and it worked fine. Then, I needed to add two more columns, and I did so using the following steps, but it’s not attaching the two new columns seed data to the table, what am I doing wrong?
Steps:
- Add two columns using migration
- Make them attr_accessible in the model
- Replace old CSV file with new CSV file
- Change the seed.rb file to plug in the new data
- Run rake db:seed
Seed.rb
require 'csv'
Model.delete_all
CSV.foreach("#{Rails.root}/lib/data/model.csv") do |row|
Model.create!(:model_number => row[0], :areq => row[1], :length => row[2], :width => row[3], :depth => row[4], :material => row[5], :frame => row[6], :edge => row[7], :tubes => row[8], :tube_length => row[9])
end
Schema.rb
create_table "models", :force => true do |t|
t.string "model_number"
t.float "areq"
t.float "length"
t.float "width"
t.float "depth"
t.string "material"
t.string "frame"
t.float "edge"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.float "tubes"
t.float "tube_length"
end
Cant say this may work 100%
Try
Model.reset_column_informationabove the seed file oncethis should refresh the columns information in table.
just a guess check if the proper model.csv is getting loaded and have column 8 and 9 means have in all 10 columns.