Ruby on Rails - adding an unique column to a table - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
To adding a new unique column email for users
- Run the given below command:
rails generate migration AddEmailToUsers email:string:uniq
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
It will create the below migration:
class AddEmailToUsers < ActiveRecord::Migration[5.0]
def change
add_column :users, :email, :string
add_index :users, :email, unique: true
end
end