【问题标题】:rails db migration, undefined method `to_sym', can't figure out syntaxrails db迁移,未定义的方法“to_sym”,无法弄清楚语法
【发布时间】:2011-02-14 13:51:39
【问题描述】:

这是我最初的迁移:

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

【问题讨论】:

  • 发布整个错误:“未定义方法”之前和之后的部分。问题是哪个类/对象引发了该错误?
  • == ChangeUserStateDefault: 迁移 ===================================== ==== -- change_column(:users, :state, {:default=>"active", :null=>:no}) rake 中止!发生错误,此迁移和所有后续迁移已取消:未定义方法 `to_sym' for {:default=>"active", :null=>:no}:Hash

标签: ruby-on-rails migration


【解决方案1】:

编辑:

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

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

所以这应该适合你:

change_column :users, :state, :string, :null => false, :default => 'active'

【讨论】:

  • 你是救生员!
猜你喜欢
  • 2017-01-11
  • 2011-06-05
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 2017-11-25
  • 1970-01-01
  • 1970-01-01
  • 2013-05-19
相关资源
最近更新 更多