Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rails db migration, undefined method `to_sym', can't figure out syntax

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
like image 424
sysconfig Avatar asked Sep 09 '25 15:09

sysconfig


1 Answers

EDIT:

The error is because you were missing the type of the column. Usage:

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

So this should work for you:

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

Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!