我是Ruby on rails的新手,我正在使用omni_auth进行facebook和google身份验证并坚持使用!
当我运行rake db:migrate时,显示以下错误:
rake aborted!
NoMethodError: undefined method `[]' for #<ActiveRecord::Migration:0x000000033fedc0>
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:664:in `block in method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `block in say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:634:in `say_with_time'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:654:in `method_missing'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:416:in `method_missing'
/home/ubuntu/rails_project/Devise-Omniauth/db/migrate/20180129115427_update_users.rb:1:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.3.0/gems/activesupport-4.2.5/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:777:in `load_migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:773:in `migration'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:768:in `disable_ddl_transaction'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:1051:in `use_transaction?'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:961:in `rescue in block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:958:in `block in migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `each'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:955:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:823:in `up'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/migration.rb:801:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/tasks/database_tasks.rb:137:in `migrate'
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/railties/databases.rake:44:in `block (2 levels) in <top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/gems/rake-12.3.0/exe/rake:27:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
/usr/local/rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'
这是由于此文件造成的:
class UpdateUsers < ActiveRecord::Migration[5.0]
def change
add_column(:users, :provider, :string, limit: 50, null: false, default: '')
add_column(:users, :uid, :string, limit: 500, null: false, default: '')
end
end
答案 0 :(得分:1)
您似乎正在使用rails 4.2。
和版本化迁移仅在rails 5中工作
只需从您的迁移中移除[5.0]
,它就能正常运行。
像:
class UpdateUsers < ActiveRecord::Migration
def change
add_column(:users, :provider, :string, limit: 50, null: false, default: '')
add_column(:users, :uid, :string, limit: 500, null: false, default: '')
end
end