Foreman 3.1.3 -> 3.2 / Katello 4.3.1 -> 4.4 db:migrate error: PG::ForeignKeyViolation on table katello_erratum_packages

Problem:
foreman-installer reports:

2022-06-03 12:58:56 [ERROR ] [configure] '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
2022-06-03 12:58:56 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: change from 'notrun' to ['0'] failed: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
2022-06-03 13:00:11 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: Failed to call refresh: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]
2022-06-03 13:00:11 [ERROR ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]: '/usr/sbin/foreman-rake db:migrate' returned 1 instead of one of [0]

/usr/sbin/foreman-rake db:migrate says:

# /usr/sbin/foreman-rake db:migrate
Rubocop not loaded.
Rubocop not loaded.
== 20220303160220 RemoveDuplicateErrata: migrating ============================
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

PG::ForeignKeyViolation: ERROR:  update or delete on table "katello_erratum_packages" violates foreign key constraint "katello_msep_erratum_package_id_fk" on table "katello_module_stream_erratum_packages"
DETAIL:  Key (id)=(359849) is still referenced from table "katello_module_stream_erratum_packages".

Expected outcome:
Successful db:migrate/foreman-installer run

Foreman and Proxy versions:
Foreman 3.1.3, Katello 4.3.1

Foreman and Proxy plugin versions:

Distribution and version:
RHEL 7.9

Has anyone had this issue before?
Any help is much appreciated. :slight_smile:

Hey @sgo ,

This has been fixed on nightly but not yet landed in 4.4.

The fixed migration is here: katello/20220303160220_remove_duplicate_errata.rb at master · Katello/katello · GitHub

You can run the migration separately by updating the /opt/theforeman/tfm/root/usr/share/gems/gems/katello-4.4/db/migrate/20220303160220_remove_duplicate_errata.rb

1 Like

@sajha Thank you so much for your quick response and helpful answer! :slight_smile:

1 Like