0
在Rails 5和PostgreSQL中。如何在使用add_reference和Rails时使用bigint类型?
我创造了这个文件,要默认使用bigint
数据类型,而不是integer
:
# 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
时:
class ChangeA < ActiveRecord::Migration[5]
def change
add_reference :posts, :users
end
end
的posts
表添加该字段:
# posts table
...
user_id integer
两个posts
和users
表ID是bigint
类型,但这一领域呢没有改变。
有没有办法为数据类型设置为add_reference
方法?