Foreman 1.9: ERROR: column hosts.last_freshcheck does not exist

If you’ve recently upgraded your Foreman 1.8 setup to 1.9, you may see the following error in your dashboard when navigating to a particular host.

# Oops, we're sorry but something went wrong

PGError: ERROR: column hosts.last_freshcheck does not exist LINE 1: ..."name" AS t1_r1, "hosts"."last_compile" AS t1_r2, "hosts"."l... ^ : SELECT "reports"."id" AS t0_r0, "reports"."host_id" AS t0_r1, "reports"."reported_at" AS t0_r2, ...

The upgrade steps will tell you to execute the following database migrations:

$ cd /usr/share/foreman
$ foreman-rake db:migrate
$ foreman-rake db:seed

You can check if the migrations were all executed correctly, by running the following command.

$ cd /usr/share/foreman
$ foreman-rake db:migrate:status
...
   up     20150618093433  Remove unused fields from hosts
   up     20150622090115  Change reported at
   up     20150714140850  Remove new from compute attributes

If the output shows “up”, it means that particular database migration script is up-to-date and was executed. Nothing to do here.

The error concerning the hosts.last_freshcheck column is a result of a cleanup issue where obsoleted columns have been removed. The resulting code is found in pull request 2471.

If your database migrations are all completed and you still see the error, restart your Apache server. The Ruby/Passengers processes keep a cache in memory of the database structure, that isn’t refreshed when running the foreman-rake db:migrate commands.