2017-03-16 11 views
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 

両方postsusersテーブルIDがbigintタイプですが、このフィールドはありません変更されません。

データ型をadd_referenceメソッドに設定する方法はありますか?

答えて

関連する問題