0
Rails 5とPostgreSQLの場合Railsでadd_referenceを使用するときにbigint型を使用するには?
私は、デフォルトではinteger
の代わりに入力しbigint
データを使用するために、このファイルを作成します。runが作成し、移行時に
# config/initializers/bigint_primary_keys.rb
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:primary_key] = 'bigserial primary key'
ので、テーブルIDは、bigint
型になります。
# posts table
id bigint not null
...
# users table
id bigint not null
...
しかし、移動中add_reference
使用:posts
表には、このフィールドを追加
class ChangeA < ActiveRecord::Migration[5]
def change
add_reference :posts, :users
end
end
を:
# posts table
...
user_id integer
両方posts
とusers
テーブルIDがbigint
タイプですが、このフィールドはありません変更されません。
データ型をadd_reference
メソッドに設定する方法はありますか?