我已经成功地用Heroku部署了我的Rails app,heroku run rails db:migrate
,尽管heroku run rails db:seed
失败了。
以下是错误消息
➜ quote-editor git:(master) heroku run rails db:seed
Running rails db:seed on ⬢ awesome-quote-editor... up, run.6832 (Free)
== Seeding the database with fixtures ==
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_c_783704777" is a system trigger
rails aborted!
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "line_item_dates" violates foreign key constraint "fk_rails_048689f618"
DETAIL: Key (quote_id)=(309456473) is not present in table "quotes".
我的设置
- Ubuntu 20.04.2版本
- Ruby 3.1.2版
- 导轨7.0.4
- 第1.4.3页,带有本机扩展
我已经尝试给予超级用户权限ALTER USER myuser WITH SUPERUSER;
和GRANT ALL PRIVILEGES ON DATABASE quote_editor_production TO myuser;
数据库列表
Name | Owner | Encoding | Collate | Ctype | Access
----------------------------- | -------- | -------- | ------- | ------- | ------------
quote_editor_development | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 |
----------------------------- | -------- | -------- | ------- | ------- | ------------
quote_editor_production | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 | =Tc/paulinetw
quote_editor_test | paulinetw | UTF8 | C.UTF-8 | C.UTF-8 |
database.yml
default: &default
adapter: postgresql
encoding: unicode
development:
<<: *default
database: quote_editor_development
test:
<<: *default
database: quote_editor_test
production:
<<: *default
database: quote_editor_production
username: quote_editor
password: <%= ENV["QUOTE_EDITOR_DATABASE_PASSWORD"] %>
我已经试过很多建议,但仍然找不到出路。如果有人能帮助我,我将非常感激。
1条答案
按热度按时间nx7onnlm1#
ActiveRecord::InvalidForeignKey: PG::ForeignKeyViolation: ERROR: insert or update on table "line_item_dates" violates foreign key constraint "fk_rails_048689f618" DETAIL: Key (quote_id)=(309456473) is not present in table "quotes".
您的种子文件正在尝试使用ID为309456473的
Quote
,但该引用不存在。更新:
以下是我的假设:
heroku run rails db:migrate
,heroku run rails db:seed
会失败。Quote.find(309456473)
的代码,这在生产中失败Quotes
时,您在创建报价时手动设置了每个报价的ID。在创建记录时设置记录的ID不是一个好主意。让Db生成键。
在种子文件中,无论您在何处按ID查找记录,都要找到一种不同的方法,以便按其他属性查找所需的记录。
不要假设Heroku Postgres会尊重或保留种子文件中的记录ID。