我创建了id为bigint的表
class Hoge < ActiveRecord::Migration
def change
create_table :hoges, id: false do |t|
t.column :id, :serial8, primary_key: true
t.integer :bar, null: false
end
end
end
并在模型中设置主键
class Hoge < ActiveRecord::Base
self.primary_key = :id
end
然后,我执行迁移,开发数据库创建成功
Column | Type | Modifiers
--------------+-----------------------------+----------------------------------------------------------
id | integer | not null default nextval('hoges_id_seq'::regclass)
bar | integer | not null
然后,我执行“rake test” 测试数据库已创建,但无效。默认为 0.....
Column | Type | Modifiers
--------------+-----------------------------+----------------------------------------------------------
id | integer | not null default 0
bar | integer | not null
为什么测试环境的数据库和开发环境不一样? (数据库是postgres)
最佳答案
您应该使用命令 rake db:test:prepare
关于ruby-on-rails - 为什么环境数据库的默认值不是同一个开发环境?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35497130/