问题
Following the instructions in https://stackoverflow.com/a/24496452/102675 I wound up with the following:
namespace :db do
desc 'Drop, create, migrate, seed and populate sample data'
task seed_sample_data: [:drop, :create, :migrate, :seed, :populate_sample_data] do
puts 'Sample Data Populated. Ready to go!'
end
desc 'Populate the database with sample data'
task populate_sample_data: :environment do
puts Inspector.column_names.include?('how_to_fix')
# create my sample data
end
end
As you would expect, I get true
if I run bundle exec rake db:populate_sample_data
BUT if I run bundle exec rake db:seed_sample_data
I get all the migration output and then false
. In other words I can't see the Inspector
attribute how_to_fix
even though it definitely exists as proved by the other rake run. Where did my attribute go?
回答1:
My guess is that this is a "caching" problem. Can you try the following?
task populate_sample_data: :environment do
Inspector.reset_column_information
# ...
end
P.S. We used to have a similar problem working with different databases having the exact same schema (only except some columns here and there)
来源:https://stackoverflow.com/questions/44381014/the-case-of-the-disappearing-activerecord-attribute