我有一张table:
create_table "gocardless_runner_infos", id: :serial, force: :cascade do |t|
t.integer "runner_id", null: false
t.string "redirect_flow_id"
t.string "redirect_flow_url"
t.string "mandate_id"
t.string "customer_id"
t.datetime "timestamp", precision: nil, null: false
end
如果我尝试用GocardlessRunnerInfo.create(runner_id: id, timestamp: DateTime.now)
创建一个示例,我会得到一个错误unknown attribute 'timestamp' for GocardlessRunnerInfo
如果我尝试在不设置时间戳的情况下创建它,那么GocardlessRunnerInfo.create(runner_id: id)
,那么它将在我的开发和生产环境中工作,但我的测试将出错:
PG::NotNullViolation: ERROR: null value in column "timestamp" of relation "gocardless_runner_infos" violates not-null constraint
DETAIL: Failing row contains (21, 1044890529, null, null, null, null, null).
(ActiveRecord::NotNullViolation)
这就像我的测试模式需要时间戳,但开发和生产不需要。知道发生了什么吗
数据库为postgres
1条答案
按热度按时间f0ofjuux1#
您的测试数据库是按预期运行的数据库:
因为你已经设置了
null: false
:有几个潜在的原因:
1.您的
development
和production
数据库没有此not null
约束。1.您的
development
和production
数据库不是Postgres,因此约束的应用方式不同1.您的
development
和production
数据库有一个默认值,如"timestamp" TIMESTAMP(6) DEFAULT NOW() NOT NULL
,它在创建时设置该值,以便满足not null
约束。