Bug #32498
closedKatello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint"
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1955397
Description of problem:
While attempting to upgrade Katello, It fails at the db:migrate stage with either of these two errors.
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_9cae1dc9a3"
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (content_view_id)=(4) is not present in table "katello_content_views".
or,
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_159087f51c"
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (lifecycle_environment_id)=(9) is not present in table "katello_environments".
Version-Release number of selected component (if applicable):
Katello 3.16 [ 3.16 to 3.17 upgrade ]
How reproducible:
Under specific circumstances i.e. the missing foreign key constraints might be the cause and somehow it bypassed the "dependent:" constraint in rails
Steps to reproduce:
1. On Katello 3.16 with CV\LCE\Hostgroups preconfigured
2. Associate a hostgroup with one CV and LCE
3. Find a way to delete that LCE or CV so that they get removed from their respective tables but the hostgroups table in DB still holds the association.
Example:
For CV --> Katello::ContentView.where(id: <cv id>).delete_all
or,
For LCE --> Katello::KTEnvironment.where(id: <lce id>).delete_all
4. Perform the upgrade to 6.9
Actual Results:
db:migrate stage will fail at following
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_9cae1dc9a3"
2021-04-28 11:23:10 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (content_view_id)=(4) is not present in table "katello_content_views".
or,
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: PG::ForeignKeyViolation: ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint "fk_rails_159087f51c"
2021-04-26 15:06:49 [INFO ] [configure] /Stage[main]/Foreman::Database/Foreman::Rake[db:migrate]/Exec[foreman-rake-db:migrate]/returns: DETAIL: Key (lifecycle_environment_id)=(9) is not present in table "katello_environments".
Expected results:
Before the db:migrate happens, these inconsistencies\stale associations should be removed from hostgroups table and then the db:migrate should be executed.
Additional Information:
Manual Solution present in https://access.redhat.com/solutions/6003311
Updated by The Foreman Bot over 3 years ago
- Status changed from New to Ready For Testing
- Assignee set to Ian Ballou
- Pull request https://github.com/Katello/katello/pull/9333 added
Updated by Ian Ballou over 3 years ago
- Subject changed from Katello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint" to Katello 3.16 to 3.17 upgrade fails at the db:migrate stage with error "ERROR: insert or update on table "katello_hostgroup_content_facets" violates foreign key constraint"
- Target version set to Katello 4.2.0
- Triaged changed from No to Yes
For the future Katello 4.2 release manager, you can leave this issue out of the release notes. It isn't relevant to those on Katello versions newer than 3.16, but triaging to 3.17 didn't make sense at the time.
Updated by The Foreman Bot over 3 years ago
- Fixed in Releases Katello 4.2.0 added
Updated by Anonymous over 3 years ago
- Status changed from Ready For Testing to Closed
Applied in changeset katello|1fbe1f1deb44592e9a04c77fdfeffd2643135043.
Updated by Jeremy Lenz over 3 years ago
- Target version changed from Katello 4.2.0 to Katello 4.1.0