ActiveRecord::InvalidForeignKey Ruby on Rails 5.1.2 Class ActiveRecord::InvalidForeignKey < ActiveRecord::WrappedDatabaseException activerecord/lib/active_record/errors.rb Raised when a record cannot be inserted or updated because it references a non-existent record.