我有一个迁移错误:
class DeviseTokenAuthCreateUsers < ActiveRecord::Migration
def change
unless column_exists? :users, :provider
add_column :users, :provider, :null => false
end
unless column_exists? :users, :uid
add_column :users, :uid, :null => false, :default => "email"
end
unless column_exists? :users, :tokens
add_column :users, :tokens, :text
end
User.reset_column_information
User.all.each{|u| u.save! }
add_index :users, [:uid, :provider], :unique => true
end
end
错误是:
undefined method `to_sym' for {:null=>false}:Hash/Users/scrivoaroby/.rvm/gems/ruby-2.0.0-p481/gems/activerecord-4.1.9/lib/active_record/connection_adapters/abstract/schema_definitions.rb:311:in `add_column'
我的rails版本是4.1.9
有什么想法吗?
答案 0 :(得分:3)
add_column
的第三个参数应该是数据类型。而不是像:
add_column :users, :provider, :null => false
你想要这样的东西,任何适合你的列的数据类型:
add_column :users, :provider, :string, :null => false
还需要对:uid
列进行此操作。