Katello upgrade from 3.12 to 3.13 failing

Problem: katello upgrade from 3.12 to 3.13 is failing at the step “Upgrade Step: migrate_foreman…”. I’m following Foreman :: Plugin Manuals for doing the upgrade.

Expected outcome:
Upgrade from katello-3.12 to katello-3.13 and foreman-1.22 to foreman-1.23

Foreman and Proxy versions:

Foreman and Proxy plugin versions:

Distribution and version:

Other relevant data:
When i run “foreman-installer --scenario katello --upgrade”, it fails at the below step throwing the below error

Upgrade Step: migrate_foreman…

[ INFO 2019-10-25T09:53:22 verbose] Upgrade Step: migrate_foreman…

rake aborted!

StandardError: An error has occurred, this and all later migrations canceled:

PG::ForeignKeyViolation: ERROR: insert or update on table “foreman_tasks_tasks” violates foreign key constraint “fk_rails_a56904dd86”

DETAIL: Key (user_id)=(5) is not present in table “users”.

: UPDATE “foreman_tasks_tasks” SET “user_id” = 5 WHERE “foreman_tasks_tasks”.“id” IN (SELECT “foreman_tasks_tasks”.“id” FROM “foreman_tasks_tasks” INNER JOIN “foreman_tasks_locks” ON “foreman_tasks_locks”.“task_id” = “foreman_tasks_tasks”.“id” WHERE “foreman_tasks_tasks”.“id” IN (SELECT “foreman_tasks_locks”.“task_id” FROM “foreman_tasks_locks” WHERE “foreman_tasks_locks”.“name” = $1 AND “foreman_tasks_locks”.“resource_id” = $2))
.
.
.
.
Caused by:
PG::ForeignKeyViolation: ERROR: insert or update on table “foreman_tasks_tasks” violates foreign key constraint “fk_rails_a56904dd86”
DETAIL: Key (user_id)=(5) is not present in table “users”.
.
.
.
.
== 20180927120509 AddUserId: migrating ========================================
– add_reference(:foreman_tasks_tasks, :user, {:type=>:integer, :foreign_key=>true})
-> 0.0116s
foreman-rake db:migrate failed! Check the output for error!

Able to bypass this issue and was able to complete the upgrade successfully after this.

  1. su - postgres
  2. psql -d foreman
  3. select * from users; --> Noticed userid ‘5’ doesn’t exist as per the error
  4. Created a dummy user with userid ‘5’
    foreman=# INSERT INTO users (id, login, firstname, lastname, mail, admin) VALUES (‘5’, ‘AB’, ‘A’, ‘B’, ‘’, ‘f’);
  5. Re-ran “foreman-installer --scenario katello --upgrade”
1 Like

Thankyou, just had the same issue and your workaround worked perfectly for me.

This is Bug #28152: PG::ForeignKeyViolation when trying to add a relation to deleted users - foreman-tasks - Foreman that will be fixed in foreman-tasks versions 1.16.3 and 1.17.2. The patch for the fix can also be safely applied to the migration manually.

1 Like