Upgrade 1.24 to 2.5 fails at db:migrate with undefined method `operatingsystems' for nil:NilClass

Problem:

I used to have a foreman 1.24 and I am upgrading to 2.5 now. However, the upgrade fails.

Expected outcome:

The command
foreman-rake db:migrate
fails with an error

NoMethodError: undefined method operatingsystems' for nil:NilClass /usr/share/foreman/db/migrate/20210115124508_template_kind_registration.rb:26:in block in up’

Foreman and Proxy versions:

see above

Foreman and Proxy plugin versions:

Distribution and version:

Ubuntu 18.04

Other relevant data:

I also tried 3.0, the issue.

here a dump:

root@puppet:/etc/apt# foreman-rake db:seed
You have 10 pending migrations:
20210115124508 TemplateKindRegistration
20210120150019 AddPositionToAnsibleRole
20210312074713 AddProviderInputs
20210317090500 AddDisksTotalToHostFacets
20210317170111 RemoveTheRemoteAddSetting
20210401124332 DropDbPendingMigrationSetting
20210525144427 EnforceUniqueTemplates
20210609093404 DropOverrideTaxonomiesFromFilter
20210610131920 RestrictSendmailLocation
2021051713291621250977 AddHostProxyInvocations

How exactly? As far as I know you can skip only one minor version when upgrading. Upgrading directly from 1.24 to 2.5 is not supported, if that’s what you are trying. You would have to go through 2.1 and 2.3 at a minimum or even through all minor version, to be sure.

You are not using katello?

3.0 has not been released. If this is a production system, I would recommend against that.

I had to comment out line 26 in
/usr/share/foreman/db/migrate/20210115124508_template_kind_registration.rb

Then, the upgrade continued and - in the end - was successful.

I doubt that. You more likely broke it in a place you haven’t noticed, yet. What you did is very dangerous. Don’t expect the system to fully work correctly. Don’t expect future updates to work correctly.

There is a reason why the migration script does what it does and simply omitting some things has the potential to break things internally resulting in weird problems and strange errors noone would ever expect…

Go to Administer - Settings - Provisioning. Check the current value for the setting “Default ‘Host initial configuration’ template”. I have “Linux host_init_config default” set there.

Now go to Hosts - Provisioning Templates. Search for the “Linux host_init_config default” template and lick on it to see the settings. Click on the Association tab and check which operating systems are associated with the template. It should be all operating systems your foreman know about. I think that’s what this line does…

Considering the code there, I guess you are missing the setting or the setting is not properly initialized. You didn’t answer, but I guess you have jumped too many version during the upgrade and lost a couple of things on the way…