Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

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

yppp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away