如何解决Rails 6最小测试ActiveRecord :: InvalidForeignKey:PG :: ForeignKeyViolation
我在Rails中运行测试时遇到问题,我已将postgres用户设置为超级用户,但仍然出现错误:
Minitest::UnexpectedError: ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "mobile_applications" violates foreign key constraint "fk_rails_5674f4d4a5"
DETAIL: Key (tenant_id)=(839733711) is not present in table "tenants".
随机失败的测试之一:
test 'mobile app should allow valid creation' do
tenant = tenants(:test_tenant)
user_tenant = user_tenants(:test_user_tenant)
mobile_app = MobileApplication.new(tenant: tenant,user_tenant: user_tenant,name: 'My New app',platform: :iOS,deploy_type: :Beta)
assert mobile_app.save
end
在模型测试(ActiveSupport :: TestCase)和葡萄API的某些集成测试(ActionDispatch :: IntegrationTest)中都可以重复使用这些夹具。
如果我运行Rails测试/模型或Rails测试/控制器,总是成功,但是如果我运行Rails测试,它每次都会以新的随机方式失败。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。