DB migration from mariadb to postgresql fails (foreman 1.18)

We have an old instance of foreman (v 1.18.3) and mariadb. The goal is to upgrade foreman to version 2 and then to version 3. First we want to switch db to postgresql (v12) but migration fails. Any help?

Problem:
Running command foreman-rake db:convert:prod2dev fails with error:

Converting hosts...rake aborted!
ActiveModel::MissingAttributeError: can't write unknown attribute `initiated_at`
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/attribute.rb:205:in `with_value_from_database'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/attribute_set.rb:54:in `write_from_user'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/attribute_methods/write.rb:39:in `write_attribute'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/attribute_methods.rb:359:in `[]='
/usr/share/foreman/lib/tasks/convert.rake:131:in `block (7 levels) in <top (required)>'
/usr/share/foreman/lib/tasks/convert.rake:130:in `each'
/usr/share/foreman/lib/tasks/convert.rake:130:in `block (6 levels) in <top (required)>'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/relation/delegation.rb:39:in `each'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/relation/delegation.rb:39:in `each'
/usr/share/foreman/lib/tasks/convert.rake:127:in `block (5 levels) in <top (required)>'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `block in transaction'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:194:in `block in within_new_transaction'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/transaction.rb:191:in `within_new_transaction'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/database_statements.rb:235:in `transaction'
/usr/share/foreman/vendor/ruby/2.3.0/gems/activerecord-5.1.6/lib/active_record/transactions.rb:210:in `transaction'
/usr/share/foreman/lib/tasks/convert.rake:126:in `block (4 levels) in <top (required)>'
/usr/share/foreman/lib/tasks/convert.rake:83:in `each'
/usr/share/foreman/lib/tasks/convert.rake:83:in `block (3 levels) in <top (required)>'
Tasks: TOP => db:convert:prod2dev
(See full trace by running task with --trace)

Expected outcome:
Migration completes without errors.

Foreman and Proxy versions:
1.18.3
Foreman and Proxy plugin versions:
No plugins
Distribution and version:
Ubuntu 16.04.7 LTS

Thank you!

Ok, so I deleted table “initiated_at” and few others.

Finaly stuck with this error, and not sure how to proceed:

Converting fact_names…rake aborted!

ActiveRecord::RecordNotUnique: PG::UniqueViolation: ERROR: duplicate key value violates unique constraint “fact_names_pkey”
DETAIL: Key (id)=(2300168) already exists.
: INSERT INTO “fact_names” (“id”, “name”, “updated_at”, “created_at”, “short_name”, “type”, “ancestry”) VALUES ($1, $2, $3, $4, $5, $6, $7)

Ok, migration was kinda successful. I manually deleted all conflicting tables from source db, and migration completed without errors. This topic can be closed now.

Ok, upgraded to foreman 1.19, everything works together with postgresql 12.

Upgrade to foreman 1.20 fails with error:
Sequel::DatabaseError: PG::UndefinedObject: ERROR: constraint “dynflow_steps_execution_plan_uuid_fkey1” of relation “dynflow_steps” does not exist

Any advice how to proceed ?

Ok, solved this by dropping table dynflow_steps and running “foreman-rake console”. This command recreated dynflow_steps with correct relations and values, and migration goes on.

I’ve managed to upgrade to Ubuntu 20 and Foreman 3.7.