I’m in the process of migrating a legacy Rails 3.22 application and I’m currently using Rails 5.2.6 and Hreoku postgresql 13.
I’ve encountered a few recurring errors that I believe are related:
- I’m hitting NULL constant errors when trying to create records for two models. Rails attempts to create the record without defining created_at. The legacy migrations are all defined as Rails 4.2 migrations and uset.timestamps. The existing database does have aNOT NULLconstraint oncreated_at,updated_atcolumns.
- I’m now noticing errors due to calling .nameon a relation of a model. The model contains the correctbelongs_toassociation, and there’s abefore_validationrule that sets the association up. Searching forModel.where(association_id: nil)returns a blank ActiveRecord collection.
Both errors magically go away when the server is restarted. Quickly copying the database to my local machine and repeating the action shows no errors.
What are my next steps to address this issue? We are planning on dumping the entire database to a file, creating a new empty database and restoring the data from the file as these problems seem to be low-level database problems rather than Ruby on Rails problems.
Does this sound sensible? Anyone else experience these errors?