Rails 7、Postgres、fixture 数据库:Rails 无法禁用引用完整性

问题描述 投票:0回答:0

我正在尝试运行我的测试套件。使用 Rails 7 和 Minitest。我目前在使我的夹具数据正常工作时遇到一些问题。当我运行

rails test
时,出现以下错误:

WARNING: Rails was not able to disable referential integrity.

This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.

cause: PG::InsufficientPrivilege: ERROR:  permission denied: "RI_ConstraintTrigger_a_217707" is a system trigger


Error:
General::ShareButtonComponentTest#test_component_renders_something_useful:
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR:  insert or update on table "addresses" violates foreign key constraint "fk_rails_d873e14e27"
DETAIL:  Key (country_id)=(156252482) is not present in table "countries".

我尝试在

psql terminal
中运行以下命令:

1: psql "db/test"
2: ALTER ROLE postgres WITH SUPERUSER

但是好像没啥作用。我的

databases.yml
文件如下所示:

default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
username: postgres
password: <%= ENV['WS_DATABASE_PASSWORD'] %>
port: 5432

development:
  <<: *default
  database: db/development

test:
  <<: *default
  database: db/test

production:
  <<: *default
  database: db/production

关于为什么我会收到这些错误有什么想法或关于如何解决它的任何提示吗?

更新

运行后

SELECT rolname, rolsuper FROM pg_roles WHERE rolname = 'postgres';
我得到以下结果:

ruby-on-rails postgresql psql fixtures minitest
© www.soinside.com 2019 - 2024. All rights reserved.