生成夹具时出错.Rails 无法禁用引用完整性



我知道轨道应该在生成夹具时禁用参照完整性。因此,经过快速的Google搜索,我发现错误以下错误的解决方案是使我的postgres用户成为超级用户。错误:

WARNING: Rails was not able to disable referential integrity.:00,  ETA: 00:00:00
This is most likely caused due to missing permissions.
Rails needs superuser privileges to disable referential integrity.
ActiveRecord::InvalidForeignKey:         ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR:  insert or update on table "responses" violates foreign key constraint "fk_rails_2ec3339f90"
DETAIL:  Key (assessment_id)=(1) is not present in table "assessments".
: INSERT INTO "joe"."responses" ("assessment_id", "user_id", "question_id", "choice_id", "created_at", "updated_at") VALUES (1, 1, 1, 1, '2017-05-08', '2017-05-08')

我认为这将很容易解决,但我的 postgres 用户已经是超级用户。我做了SHOW is_superuser;,回应是on.我什至使用alter table responses disable trigger all;从同一用户的命令行手动禁用了所有触发器。当我使用du列出 postgres 用户时,属性显示为Superuser, Create role, Create DB

我非常有信心我的用户是超级用户。这里一定还有其他事情发生。我正在使用公寓宝石进行多租户。感谢帮助。如果您需要更多代码,请告诉我。

config/database.yml中指定的用户 - 假设rails_deploy_user需要定义超级用户权限,而不是通用 postgres 用户。

psql database_environment
du;  # find psql defined users and roles
ALTER ROLE rails_deploy_user WITH SUPERUSER;

最新更新