Foreman-rake db:seed failure / Failed upgrade to katello 4.2 / foreman 3.0.1

Problem:
Running foreman-rake db:seed leads to :

User with login admin already exists, not seeding as admin.
rake aborted!
ActiveRecord::RecordInvalid: Validation failed: Name has already been taken
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/validations.rb:80:in `raise_validation_error'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/validations.rb:53:in `save!'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:318:in `block in save!'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:375:in `block in with_transaction_returning_status'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/database_statements.rb:278:in `transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:212:in `transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:366:in `with_transaction_returning_status'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:318:in `save!'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/suppressor.rb:48:in `save!'
/usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:6:in `block (2 levels) in <top (required)>'
/usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:3:in `each'
/usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:3:in `block in <top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/audited-4.9.0/lib/audited/auditor.rb:376:in `without_auditing'
/usr/share/foreman/db/seeds.d/070-provisioning_templates.rb:2:in `<top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `load'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `block in load'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:291:in `load_dependency'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `load'
/usr/share/foreman/app/services/foreman_seeder.rb:51:in `block (3 levels) in execute'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:108:in `as'
/usr/share/foreman/app/models/concerns/foreman/thread_session.rb:114:in `as_anonymous_admin'
/usr/share/foreman/app/services/foreman_seeder.rb:50:in `block (2 levels) in execute'
/usr/share/foreman/app/services/foreman_seeder.rb:44:in `each'
/usr/share/foreman/app/services/foreman_seeder.rb:44:in `block in execute'
/usr/share/foreman/lib/foreman/advisory_lock_manager.rb:20:in `block in with_transaction_lock'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `block in transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/transaction.rb:280:in `block in within_new_transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/transaction.rb:278:in `within_new_transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/connection_adapters/abstract/database_statements.rb:280:in `transaction'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/transactions.rb:212:in `transaction'
/usr/share/foreman/lib/foreman/advisory_lock_manager.rb:17:in `with_transaction_lock'
/usr/share/foreman/app/services/foreman_seeder.rb:38:in `execute'
/usr/share/foreman/db/seeds.rb:14:in `<top (required)>'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `load'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `block in load'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:291:in `load_dependency'
/opt/theforeman/tfm/root/usr/share/gems/gems/activesupport-6.0.3.7/lib/active_support/dependencies.rb:318:in `load'
/usr/share/foreman/config/initializers/0_print_time_spent.rb:38:in `block in load'
/usr/share/foreman/config/initializers/0_print_time_spent.rb:17:in `benchmark'
/usr/share/foreman/config/initializers/0_print_time_spent.rb:38:in `load'
/opt/theforeman/tfm/root/usr/share/gems/gems/railties-6.0.3.7/lib/rails/engine.rb:559:in `load_seed'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/tasks/database_tasks.rb:440:in `load_seed'
/opt/theforeman/tfm/root/usr/share/gems/gems/activerecord-6.0.3.7/lib/active_record/railties/databases.rake:331:in `block (2 levels) in <top (required)>'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:281:in `block in execute'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:281:in `each'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:281:in `execute'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:199:in `synchronize'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:83:in `block in run'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
/opt/rh/rh-ruby27/root/usr/share/gems/gems/rake-13.0.1/exe/rake:27:in `<top (required)>'
/opt/rh/rh-ruby27/root/usr/bin/rake:23:in `load'
/opt/rh/rh-ruby27/root/usr/bin/rake:23:in `<main>'
Tasks: TOP => db:seed

A similar error occured during my upgrade to katello4/foreman3 however i managed to work past it by using the following steps:

su - postgres -c "echo \"SELECT a.id,a.name,a.locked,a.type,a.created_at FROM templates a JOIN (SELECT name, COUNT(*) FROM templates GROUP BY name HAVING count(*) > 1 ) b ON a.name = b.name ORDER BY a.name;\" | psql foreman"  

and renaming the 3 duplicated templates.

It appears that at least one of these templates was the Kickstart Default and this has lead to issues registering new hosts.

Similarly, when running foreman-installer it leads to the following error:

[ERROR ] [configure] Proxy ###hostname### has failed to load one or more features (Registration), check /var/log/foreman-proxy/proxy.log for configuration errors
2021-11-12 14:47:33 [ERROR ] [configure] /Stage[main]/Foreman_proxy::Register/Foreman_smartproxy[###hostname###]/features: change from ["Ansible", "Discovery", "Dynflow", "Logs", "Openscap", "Pulpcore", "Puppet", "Puppet CA", "SSH", "TFTP", "Templates"] to ["Ansible", "Discovery", "Dynflow", "Logs", "Openscap", "Pulpcore", "Puppet", "Puppet CA", "Registration", "SSH", "TFTP", "Templates"] failed: Proxy ###hostname### has failed to load one or more features (Registration), check /var/log/foreman-proxy/proxy.log for configuration errors

Is it a case of fixing one of these problems fixes the other?

excerpt of proxy.log around relevant error:

2021-11-12 14:47:33 [DEBUG ] [configure] Datacat_collector[foreman_proxy::enabled_features](provider=datacat_collector): Selecting source_key features
2021-11-12 14:47:33 [DEBUG ] [configure] Datacat_collector[foreman_proxy::enabled_features](provider=datacat_collector): Now setting field :features
2021-11-12 14:47:33 [DEBUG ] [configure] /Stage[main]/Foreman_proxy::Register/Datacat_collector[foreman_proxy::enabled_features]: Evaluated in 0.01 seconds
2021-11-12 14:47:33 [DEBUG ] [configure] /Stage[main]/Foreman_proxy::Register/Foreman_smartproxy[###hostname###]: Starting to evaluate the resource (2201 of 2225)
2021-11-12 14:47:33 [DEBUG ] [configure] Foreman_smartproxy[###hostname###](provider=rest_v3): Making get request to https://###hostname###/api/v2/smart_proxies?search=name%3D%22###hostname###%22
2021-11-12 14:47:33 [DEBUG ] [configure] Foreman_smartproxy[###hostname###](provider=rest_v3): Received response 200 from request to https://###hostname###/api/v2/smart_proxies?search=name%3D%22###hostname###%22
2021-11-12 14:47:33 [DEBUG ] [configure] Foreman_smartproxy[###hostname###](provider=rest_v3): Making put request to https://###hostname###/api/v2/smart_proxies/1/refresh
2021-11-12 14:47:33 [DEBUG ] [configure] Foreman_smartproxy[###hostname###](provider=rest_v3): Received response 200 from request to https://###hostname###/api/v2/smart_proxies/1/refresh
2021-11-12 14:47:33 [ERROR ] [configure] Proxy ###hostname### has failed to load one or more features (Registration), check /var/log/foreman-proxy/proxy.log for configuration errors
2021-11-12 14:47:33 [ERROR ] [configure] /Stage[main]/Foreman_proxy::Register/Foreman_smartproxy[###hostname###]/features: change from ["Ansible", "Discovery", "Dynflow", "Logs", "Openscap", "Pulpcore", "Puppet", "Puppet CA", "SSH", "TFTP", "Templates"] to ["Ansible", "Discovery", "Dynflow", "Logs", "Openscap", "Pulpcore", "Puppet", "Puppet CA", "Registration", "SSH", "TFTP", "Templates"] failed: Proxy ###hostname### has failed to load one or more features (Registration), check /var/log/foreman-proxy/proxy.log for configuration errors
2021-11-12 14:47:33 [DEBUG ] [configure] /Stage[main]/Foreman_proxy::Register/Foreman_smartproxy[###hostname###]: Evaluated in 0.48 seconds
2021-11-12 14:47:33 [DEBUG ] [configure] Class[Foreman_proxy::Register]: Starting to evaluate the resource (2202 of 2225)