LoginSignup
1
2

More than 5 years have passed since last update.

migrationでIDにbigintを使用する、外部キーにbigintを指定する

Posted at

IDにbigintを使用する方法

createテーブルのキーワード引数(ID)にbigintを渡す

外部キーにbigintを指定する方法

t.referencesでlimitを指定してあげる

class Users < ActiveRecord::Migration[5.0]
  def change
    create_table :users, id: :bigint do |t|
      t.references :company, foreign_key: true, limit: 8
      t.string :name

      t.timestamps
    end
  end
end

1
2
0

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
1
2