Rails 5 - PG::UndefinedTable: ERROR: relation "application_records" does not exist Rails 5 - PG::UndefinedTable: ERROR: relation "application_records" does not exist postgresql postgresql

Rails 5 - PG::UndefinedTable: ERROR: relation "application_records" does not exist


The

PG::UndefinedTable: ERROR:  relation "application_records" does not exist

error also happens if you remove the line:

self.abstract_class = true

from app/models/application_record.rb

That line lets Rails know that this is not a model that should ever be persisted to the database, there's a good summary of Rails' abstract classes here: https://medium.com/@jeremy_96642/deep-rails-how-to-use-abstract-classes-6aee9b686e75


Answering My own question, so it may help others running into similar issues.

As metioned by @PrathameshSonpatki on the rails issue, this happens because userstamp gem injects relationships on ActiveRecord::Base rather than ApplicationRecord. (Note that userstamp gem isn't rails 5 compatible at the time of this writing).

If you have a gem not yet tested with rails 5 and you get an issue where active_support goes looking for a table called application_records, check if one of the gems you are using injects relationships on the ActiveRecord::Base class. Based on this blog post, the very purpose of ApplicationRecord is to avoid global injection of ActiveRecord::Base. Therefore you'd need to look for a version of such gem that is compatible with Rails 5 or patch such gem to inject the necessary behavior into ApplicaitonRecord instead of ActiveRecord::Base.