当我进入rails控制台并执行命令River.all查看我的数据库时,它仍然具有第一个代码块的属性,而不是第二个我更新了每条河流的属性的属性。我该如何解决这个问题?
原始db / migrate / 12123234125_create_rivers:
class CreateRivers < ActiveRecord::Migration
def change
create_table :rivers do |t|
t.date :date
t.decimal :level
t.integer :river_id
t.timestamps
end
end
end
更改版本:
class CreateRivers < ActiveRecord::Migration
def change
create_table :rivers do |t|
t.string :river_id
t.string :display
t.integer :river_id
t.timestamps
end
end
end
我也在data_import.rake文件
中有这个 task rivers: :environment do
doc = REXML::Document.new File.new("#{root_dir}/config/RiverStations.xml")
doc.elements.each("DEFINITIONS/STATIONS/STATION") { |element|
river = River.create(river_id: element.attributes["ID"], display: element.attributes["DISPLAY"], river_name: element.attributes["RIVER_NAME"])
}
在我检查之前是否有可能没有加载?
您要求的错误:
Jennys-MacBook-Pro:dashboard jennymandl$ rake db:migrate --trace
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
== 20140609150804 CreateRivers: migrating =====================================
-- create_table(:rivers)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
undefined method `write' for :display:Symbol/Users/jennymandl/Desktop/dashboard/db/migrate/20140609150804_create_rivers.rb:5:in `display'
/Users/jennymandl/Desktop/dashboard/db/migrate/20140609150804_create_rivers.rb:5:in `block in change'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/schema_statements.rb:198:in `create_table'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:649:in `block in method_missing'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `block in say_with_time'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:621:in `say_with_time'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:641:in `method_missing'
/Users/jennymandl/Desktop/dashboard/db/migrate/20140609150804_create_rivers.rb:3:in `change'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:595:in `exec_migration'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:579:in `block (2 levels) in migrate'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/benchmark.rb:281:in `measure'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:578:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:294:in `with_connection'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:577:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:752:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:992:in `block in execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `block in ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `block in transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:219:in `within_new_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/abstract/database_statements.rb:211:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/transactions.rb:208:in `transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:1038:in `ddl_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:991:in `execute_migration_in_transaction'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:953:in `block in migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `each'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:949:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:807:in `up'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/migration.rb:785:in `migrate'
/Library/Ruby/Gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `call'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:240:in `block in execute'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:235:in `execute'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:172:in `invoke_with_call_chain'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/task.rb:165:in `invoke'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:150:in `invoke_task'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block (2 levels) in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `each'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:106:in `block in top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:115:in `run_with_threads'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:100:in `top_level'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:78:in `block in run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:176:in `standard_exception_handling'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/lib/rake/application.rb:75:in `run'
/Library/Ruby/Gems/2.0.0/gems/rake-10.3.1/bin/rake:33:in `<top (required)>'
/usr/bin/rake:23:in `load'
/usr/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
Jennys-MacBook-Pro:dashboard jennymandl$