Rails 数据库迁移,未定义方法“to_sym”,无法弄清楚语法
这是我原来的迁移:
class CreateUsers < ActiveRecord::Migration
def self.up
ActiveRecord::Base.transaction do
create_table "users", :force => true do |t|
t.string :login, :limit => 40
t.string :name, :limit => 100, :default => '', :null => true
t.string :email, :limit => 100
t.string :crypted_password, :limit => 40
t.string :salt, :limit => 40
t.string :remember_token, :limit => 40
t.datetime :remember_token_expires_at
t.string :activation_code, :limit => 40
t.datetime :activated_at, :datetime
t.string :state, :null => :no, :default => 'passive'
t.datetime :deleted_at
t.integer :occupation_id, :null => :yes
t.datetime :paid_up_to_date, :date
t.timestamps
end
我正在尝试将“状态”的默认值更改为“主动”而不是被动 这是我的第二次尝试;
class ChangeUserStateDefault < ActiveRecord::Migration
def self.up
change_column :users, :state, :null => :no, :default => 'active'
end
Here is my original migration:
class CreateUsers < ActiveRecord::Migration
def self.up
ActiveRecord::Base.transaction do
create_table "users", :force => true do |t|
t.string :login, :limit => 40
t.string :name, :limit => 100, :default => '', :null => true
t.string :email, :limit => 100
t.string :crypted_password, :limit => 40
t.string :salt, :limit => 40
t.string :remember_token, :limit => 40
t.datetime :remember_token_expires_at
t.string :activation_code, :limit => 40
t.datetime :activated_at, :datetime
t.string :state, :null => :no, :default => 'passive'
t.datetime :deleted_at
t.integer :occupation_id, :null => :yes
t.datetime :paid_up_to_date, :date
t.timestamps
end
I am trying to change the default of "state" to be "active" instead of passive
Here is my second attempt;
class ChangeUserStateDefault < ActiveRecord::Migration
def self.up
change_column :users, :state, :null => :no, :default => 'active'
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
错误是因为您缺少列的类型。
用法:
所以这应该适合你:
EDIT:
The error is because you were missing the type of the column.
Usage:
So this should work for you: