7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

railsでテーブル作成と同時にインデックスを貼る

Last updated at Posted at 2018-02-21

表題の通り。

下記のように書く。

class CreateTweets < ActiveRecord::Migration[5.1]
  def change
    create_table :tweets do |t|
      t.string :tweet_id

      t.timestamps

      t.index :tweet_id, unique: true
    end
  end
end

参考
activerecord - How to Create a New Table With a Unique Index in an Active Record / Rails 4 Migration - Stack Overflow

7
5
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?