Heroku and Mysterious `nil` Errors

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:

  1. 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 use t.timestamps. The existing database does have a NOT NULL constraint on created_at, updated_at columns.
  2. I’m now noticing errors due to calling .name on a relation of a model. The model contains the correct belongs_to association, and there’s a before_validation rule that sets the association up. Searching for Model.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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs