"", :null => false add_index :users, :email, :unique => true I want to cre...">

Rails 3 Migration

Current Migration:

t.string "email", :default => "", :null => false add_index :users, :email, :unique => true 

I want to create a new migration to remove the requirement :null => false , and also remove default => "" for email . Also, I would like to change the index to remove :unique => true . What is the syntax?

+4
source share
1 answer

I haven’t done much with indexes, and there is no change_index method on ActiveRecord::Migration , but you can try something like this:

 class ChangeUserStuff < ActiveRecord::Migration def self.up change_column :users, :email, :default => "", :null => true remove_index :users, :column => :email add_index :users, :email end def self.down change_column :users, :email, :default => "", :null => false remove_index :users, :column => :email add_index :users, :email, :unique => true end end 

There was some ridiculous behavior regarding changing options :null , but I believe that setting them to true instead of omitting it, should handle it.

+6
source

All Articles