如果有人能帮助至少了解问题的来源,我将不胜感激。
我在使用我正在进行的项目进行迁移时遇到了问题。我甚至开始了一个全新的,但问题仍然是保证相同。尝试执行rake db:migrate时出现错误消息 (已尝试使用默认的database-sqlite3和可选的postgresql启动新项目),但是,在生成模型后(尝试使用rails g scaffold计划名称:名称dep_date:datetime和只是模型 - rails g model计划名称:名称dep_date:datetime)迁移停留。
迁移本身是:
class CreateSchedules < ActiveRecord::Migration[5.0]
def change
create_table :schedules do |t|
t.name :name
t.datetime :dep_date
t.timestamps
end
end
end
命令:rake db:migrate:status
给出以下内容:
database: travel_t_challenge_development
Status Migration ID Migration Name
down 20160809121048 Create schedules
命令:
rake db:migrate
rake RAILS_ENV=production db:migrate or
rake db:migrate:up VERSION=20160809121048 or
bundle exec rake db:migrate VERSION=20160809121048
(或重做)
会导致同样的错误:
== 20160809121048 CreateSchedules: migrating ==================================
-- create_table(:schedules)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
wrong number of arguments (1 for 0)
/Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:4:in block in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:277:increate_table'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in block in method_missing' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:inblock in say_with_time'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in say_with_time' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:inmethod_missing'
/Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:3:in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:inexec_migration'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in block (2 levels) in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:inblock in migrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:inmigrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:inblock in execute_migration_in_transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in block in ddl_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:inblock in transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:intransaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inddl_transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in execute_migration_in_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:inblock in migrate_without_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in each' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:inmigrate_without_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in block in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:inwith_advisory_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:inup'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:989:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:inmigrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>' /Users/[username]/.rvm/gems/ruby-2.2.2/gems/rake-11.2.2/exe/rake:27:in'
/Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in eval' /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in'
ArgumentError: wrong number of arguments (1 for 0)
/Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:4:in block in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/schema_statements.rb:277:increate_table'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:845:in block in method_missing' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:inblock in say_with_time'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:814:in say_with_time' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:834:inmethod_missing'
/Users/[username]/workspace/travel_t_challenge/db/migrate/20160809121048_create_schedules.rb:3:in change' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:788:inexec_migration'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:772:in block (2 levels) in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:771:inblock in migrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:398:in with_connection' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:770:inmigrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:950:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1211:inblock in execute_migration_in_transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:in block in ddl_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:inblock in transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/transaction.rb:189:in within_new_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/connection_adapters/abstract/database_statements.rb:232:intransaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/transactions.rb:211:in transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1279:inddl_transaction'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1210:in execute_migration_in_transaction' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1183:inblock in migrate_without_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:in each' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1182:inmigrate_without_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in block in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1298:inwith_advisory_lock'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1131:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:1005:inup'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/migration.rb:989:in migrate' /Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/tasks/database_tasks.rb:161:inmigrate'
/Users/[username]/.rvm/gems/ruby-2.2.2@global/gems/activerecord-5.0.0/lib/active_record/railties/databases.rake:58:in block (2 levels) in <top (required)>' /Users/[username]/.rvm/gems/ruby-2.2.2/gems/rake-11.2.2/exe/rake:27:in'
/Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in eval' /Users/[username]/.rvm/gems/ruby-2.2.2/bin/ruby_executable_hooks:15:in'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
再次删除和设置/创建数据库也没有帮助。
系统配置
Rails版本:5.0.0 Ruby版本:2.2.3
答案 0 :(得分:1)
尝试此操作,替换CreateSchedules迁移的更改方法。
def change
create_table :schedules do |t|
t.string :name
t.datetime :dep_date
t.timestamps null: false
end
end