Red Hat Satellite 6.10 upgrade fails with PG::NotNullViolation: ERROR: column "subscription_id" contains null values

Solution Verified - Updated -

Environment

  • Red Hat Satelite 6.10

Issue

  • Upgrading Red Hat Satellite to 6.10 fails at db:migrate step with below error:

    PG::NotNullViolation: ERROR:  column "subscription_id" contains null values
    

Resolution

  • Run below commands on Satellite as a workaround of BugZilla 2023809

    # foreman-rake console
       ::Katello::Pool.where(subscription_id: nil).destroy_all
    
  • Attempt Satellite upgrade again.

Root Cause

  • This issue has been highlighted to Red Hat Engineering team and is being tracked under BugZilla 2023809

Diagnostic Steps

  • Running foreman-rake db:migrate command fails with below error:

    # foreman-rake db:migrate --trace
    'ErbParser' is ignored.
    'RubyParser' is ignored.
    ** Invoke db:migrate (first_time)
    ** Invoke db:load_config (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    API controllers newer than Apipie cache! Run apipie:cache rake task to regenerate cache.
    ** Execute db:load_config
    ** Invoke plugin:refresh_migrations (first_time)
    ** Invoke environment
    ** Execute plugin:refresh_migrations
    ** Execute db:migrate
    == 20210331180353 KatelloPoolOrganizationIdNotNullable: migrating =============
    -- change_column(:katello_pools, :organization_id, :integer, {:null=>false})
      -> 0.0023s
    -- change_column(:katello_pools, :subscription_id, :integer, {:null=>false})
    rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    PG::NotNullViolation: ERROR:  column "subscription_id" contains null values
    

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.