5

I have added created new migration:

class AddColumnsToDiscipline < ActiveRecord::Migration
 def change
   add_column :disciplines, :days, :integer, array: true
 end
end

Then I have run migration.

In my seed.rb file I have added this

t.disciplines.create(name: Company.name, days: [1, 2, 3])

After when I run rake db:seed, When I run my rails console all created models days attribute has nil value. Whad did I miss?

2
  • 1
    try this with default value and not integer add_column :disciplines, :days, :text, array: true, default: [] in your migration file and then run rake db:seed command Commented Apr 14, 2015 at 9:03
  • what is your database?. Commented Apr 14, 2015 at 9:40

2 Answers 2

7

try this with default option

add_column :disciplines, :days, :integer, array: true, default: [] 

in your migration file and then

run rake db:seed

EDIT

Try as

add_column :disciplines, :days, :integer, array: true, default: '{}' 

and change create to create!

t.disciplines.create!(name: Company.name, days: [1, 2, 3])

If you are using strong parameters have you permitted days in your controller

Sign up to request clarification or add additional context in comments.

7 Comments

I have added default: [] and remigrated my database. Then run seed, still gives me nil
@Mr.D Try as add_column :disciplines, :days, :integer, array: true, default: '{}'
I have tried this changed [] to '{}'. Still the same
@Mr.D - are you using strong parameters?
I'm Using rails 4. That means yes?
|
0

This issue was opened in rails public repo. follow this.

rails 4-0-stable have come with that fix. Maybe you need to update the rails version :D.

2 Comments

I have rails 4.1 version
oops. may other can help you now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.