Rails 资金迁移失败
Rails Money migration fails
我正在尝试导入所有迁移。但是,在 create_table 块中使用 t.monetize :total, currency: { present: false }
似乎会崩溃,并显示以下错误消息:
class AddAddressAndOrder < ActiveRecord::Migration[5.1]
def change
create_table :line_items do |t|
t.belongs_to :order
t.integer :quantity, default: 0
t.monetize :price, currency: { present: false }
t.monetize :total, currency: { present: false }
t.timestamps
end
end
end
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2..3)
每次我到达 t.monetize(或 t.money)列引用时,我都会收到相同的错误...在下面添加(包括 --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
== 20160901101357 AddAddressAndOrder: migrating ===============================
-- create_table(:orders)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0@global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0@global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
我的 Gemfile.lock 在金钱方面看起来是这样的-Rails:
money (~> 6.10.1)
money-rails (1.10.0)
activesupport (>= 3.0)
monetize (~> 1.7.0)
money (~> 6.10.0)
railties (>= 3.0)
文档 (https://github.com/RubyMoney/money-rails#migration-helpers) 指出这应该没问题。所以我不知道该怎么办。
问题似乎出在 MoneyRails::ActiveRecord::Migration::Table.monetize
方法中:
module MoneyRails
module ActiveRecord
module MigrationExtensions
module Table
def monetize(accessor, options={})
[:amount, :currency].each do |attribute|
column_present, _, *opts = OptionsExtractor.extract attribute, :no_table, accessor, options
column(*opts) if column_present
end
end
# Removed for brevity
end
end
end
end
无论传递什么给货币化,它似乎总是抛出相同的错误。我真的不知道我做错了什么,所以任何帮助将不胜感激。
您是否在初始化程序中执行了任何可能影响 MoneyRails::Configuration#amount_column
的操作?看起来 OptionsExtractor
缺少一些东西。
我正在尝试导入所有迁移。但是,在 create_table 块中使用 t.monetize :total, currency: { present: false }
似乎会崩溃,并显示以下错误消息:
class AddAddressAndOrder < ActiveRecord::Migration[5.1]
def change
create_table :line_items do |t|
t.belongs_to :order
t.integer :quantity, default: 0
t.monetize :price, currency: { present: false }
t.monetize :total, currency: { present: false }
t.timestamps
end
end
end
*** ArgumentError Exception: wrong number of arguments (given 1, expected 2..3)
每次我到达 t.monetize(或 t.money)列引用时,我都会收到相同的错误...在下面添加(包括 --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
== 20160901101357 AddAddressAndOrder: migrating ===============================
-- create_table(:orders)
rake aborted!
StandardError: An error has occurred, all later migrations canceled:
wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0@global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Caused by:
ArgumentError: wrong number of arguments (given 1, expected 2..3)
schema_definitions.rb:311:in `column'
table_pg_rails4.rb:9:in `block in monetize'
table_pg_rails4.rb:6:in `each'
table_pg_rails4.rb:6:in `monetize'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:20:in `block in change'
schema_statements.rb:282:in `create_table'
abstract_mysql_adapter.rb:363:in `create_table'
method_missing'
say_with_time'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
`method_missing'
/Users/Paul/folder/Sites/project/db/migrate/20160901101357_add_address_and_order.rb:18:in `change'
`exec_migration'
migrate'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/benchmark.rb:293:in `measure'
migrate'
connection_pool.rb:408:in `with_connection'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
execute_migration_in_transaction'
`ddl_transaction'
`execute_migration_in_transaction'
migrate_without_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
`migrate_without_lock'
migrate'
`with_advisory_lock'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/Users/Paul/.rvm/gems/ruby-2.5.0@project/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
`migrate'
levels) in <top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
`invoke_with_call_chain'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
top_level'
`run_with_threads'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
`standard_exception_handling'
/Users/Paul/.rvm/rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/Users/Paul/.rvm/gems/ruby-2.5.0@global/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `load'
/Users/Paul/.rvm/rubies/ruby-2.5.0/bin/rake:23:in `<main>'
Tasks: TOP => db:migrate
我的 Gemfile.lock 在金钱方面看起来是这样的-Rails:
money (~> 6.10.1)
money-rails (1.10.0)
activesupport (>= 3.0)
monetize (~> 1.7.0)
money (~> 6.10.0)
railties (>= 3.0)
文档 (https://github.com/RubyMoney/money-rails#migration-helpers) 指出这应该没问题。所以我不知道该怎么办。
问题似乎出在 MoneyRails::ActiveRecord::Migration::Table.monetize
方法中:
module MoneyRails
module ActiveRecord
module MigrationExtensions
module Table
def monetize(accessor, options={})
[:amount, :currency].each do |attribute|
column_present, _, *opts = OptionsExtractor.extract attribute, :no_table, accessor, options
column(*opts) if column_present
end
end
# Removed for brevity
end
end
end
end
无论传递什么给货币化,它似乎总是抛出相同的错误。我真的不知道我做错了什么,所以任何帮助将不胜感激。
您是否在初始化程序中执行了任何可能影响 MoneyRails::Configuration#amount_column
的操作?看起来 OptionsExtractor
缺少一些东西。