Rails / Heroku迁移错误参数数量错误(给定1,预期为0)

时间:2018-01-29 18:54:57

标签: ruby-on-rails ruby heroku migration

尝试运行heroku run rake db:migrate时出错。这个错误的有趣之处在于我没有在本地获取它,也没有在生产服务器上获取它(也在Heroku上)。只有登台服务器遇到此问题。

似乎特定迁移中的时间戳会引发错误:

rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'

...

Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'

以下是迁移文件/app/db/migrate/20170609154646_create_orders.rb

class CreateOrders < ActiveRecord::Migration[5.0]
  def change
    create_table :orders do |t|
      t.string :source, null: false
      t.integer :source_order_id 
      t.integer :customer_id, null: false
      t.string :type
      t.boolean :fulfilled, default: false
      t.timestamps :fullfilled_date
      t.boolean :arrived, default: false
      t.timestamps :arrived_date
      t.timestamps :due_date
      t.boolean :late, default: false
      t.text :requester_notes
      t.text :provider_notes
      t.float :subtotal, null: false
      t.float :total, null: false
      t.float :discount
      t.references :provider, references: :tailors, index: true
      t.references :requester, references: :retailers, index: true
      t.timestamps
    end
  end
end

完整的堆栈跟踪:

λ ~: heroku run rake db:migrate -a [app-name] --trace
Running rake db:migrate --trace on ⬢ [app-name]... up, run.2263 (Free)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Execute db:load_config
** Execute db:migrate
D, [2018-01-29T18:44:23.091296 #4] DEBUG -- :    (21.4ms)  SELECT pg_try_advisory_lock(2914900371259544535)
D, [2018-01-29T18:44:23.203445 #4] DEBUG -- :    (16.6ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
I, [2018-01-29T18:44:23.207416 #4]  INFO -- : Migrating to CreateOrders (20170609154646)
D, [2018-01-29T18:44:23.230850 #4] DEBUG -- :    (19.2ms)  BEGIN
== 20170609154646 CreateOrders: migrating =====================================
-- adapter_name()
   -> 0.0000s
-- adapter_name()
   -> 0.0000s
-- create_table(:orders, {:id=>:integer})
D, [2018-01-29T18:44:23.246188 #4] DEBUG -- :    (9.3ms)  ROLLBACK
D, [2018-01-29T18:44:23.256813 #4] DEBUG -- :    (9.8ms)  SELECT pg_advisory_unlock(2914900371259544535)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:49:in `block in create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
/app/db/migrate/20170609154646_create_orders.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/airbrake-7.1.0/lib/airbrake/rake.rb:19:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `load'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:360:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:10:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'

Caused by:
ArgumentError: wrong number of arguments (given 1, expected 0)
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_definitions.rb:351:in `timestamps'
/app/db/migrate/20170609154646_create_orders.rb:9:in `block in change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:49:in `block in create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/schema_statements.rb:282:in `create_table'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:849:in `block in method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `block in say_with_time'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:818:in `say_with_time'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:838:in `method_missing'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration/compatibility.rb:45:in `create_table'
/app/db/migrate/20170609154646_create_orders.rb:3:in `change'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:792:in `exec_migration'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:776:in `block (2 levels) in migrate'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:293:in `measure'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:775:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/connection_pool.rb:408:in `with_connection'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:774:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:953:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1230:in `block in execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `block in ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/transactions.rb:210:in `transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1298:in `ddl_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1229:in `execute_migration_in_transaction'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1201:in `block in migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1200:in `migrate_without_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `block in migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1317:in `with_advisory_lock'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1148:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:1007:in `up'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/migration.rb:985:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/tasks/database_tasks.rb:171:in `migrate'
/app/vendor/bundle/ruby/2.3.0/gems/activerecord-5.1.4/lib/active_record/railties/databases.rake:58:in `block (2 levels) in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `block in execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:251:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/airbrake-7.1.0/lib/airbrake/rake.rb:19:in `execute'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:195:in `block in invoke_with_call_chain'
/app/vendor/ruby-2.3.4/lib/ruby/2.3.0/monitor.rb:214:in `mon_synchronize'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:188:in `invoke_with_call_chain'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/task.rb:181:in `invoke'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:160:in `invoke_task'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `each'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:116:in `block in top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:125:in `run_with_threads'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:110:in `top_level'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:83:in `block in run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:186:in `standard_exception_handling'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/lib/rake/application.rb:80:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `load'
/app/vendor/bundle/ruby/2.3.0/bin/rake:22:in `<top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:74:in `kernel_load'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli/exec.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:360:in `exec'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor.rb:369:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:20:in `dispatch'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/vendor/thor/lib/thor/base.rb:444:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/cli.rb:10:in `start'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:30:in `block in <top (required)>'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/lib/bundler/friendly_errors.rb:121:in `with_friendly_errors'
/app/vendor/bundle/ruby/2.3.0/gems/bundler-1.15.2/exe/bundle:22:in `<top (required)>'
/app/bin/bundle:3:in `load'
/app/bin/bundle:3:in `<main>'
Tasks: TOP => db:migrate

如果有任何想法可能导致这一点,我们将不胜感激!

1 个答案:

答案 0 :(得分:1)

您应该使用datetime代替时间戳来填充列&quot; fullfilled_date&#39;,&#39; arri_date&#39;和&#39; due_date&#39;因为时间戳不会带任何参数

  def change
    create_table :orders do |t|
      t.string :source, null: false
      t.integer :source_order_id 
      t.integer :customer_id, null: false
      t.string :type
      t.boolean :fulfilled, default: false
      t.datetime :fullfilled_date
      t.boolean :arrived, default: false
      t.datetime :arrived_date
      t.datetime :due_date
      t.boolean :late, default: false
      t.text :requester_notes
      t.text :provider_notes
      t.float :subtotal, null: false
      t.float :total, null: false
      t.float :discount
      t.references :provider, references: :tailors, index: true
      t.references :requester, references: :retailers, index: true
      t.timestamps
    end
  end