gpt4 book ai didi

ruby-on-rails - rails db 迁移,未定义的方法 `to_sym' ,无法弄清楚语法

转载 作者:行者123 更新时间:2023-12-03 11:04:02 25 4
gpt4 key购买 nike

这是我的原始迁移:

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

最佳答案

编辑:

错误是因为您缺少列的类型。
Usage :

change_column(table_name, column_name, type, options = {})


所以这应该适合你:
change_column :users, :state, :string, :null => false, :default => 'active'

关于ruby-on-rails - rails db 迁移,未定义的方法 `to_sym' ,无法弄清楚语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2750410/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com