Answers for "rails migration create table table column add index unique"

0

how do I add index's to a migration in rails

rails generate migration AddUser_idColumnToTable user_id:string. 

class AddIndexToTable < ActiveRecord::Migration
  def change
    add_index :table, :user_id
  end
end
Posted by: Guest on February-14-2020
0

create table index unique rails

class CreateFoobars < ActiveRecord::Migration
  def change
    create_table :foobars do |t|
      t.string :name, index: {unique: true}
    end
  end
end
Posted by: Guest on August-21-2021

Code answers related to "rails migration create table table column add index unique"

Browse Popular Code Answers by Language