首页 > 解决方案 > Rails creates weird mysql requests in RACK_ENV=production

问题描述

We are trying to migrate from rails 4 to rails 5 and have an error, where it says we have a null violation for one of our fields: created_at in this code:

version_set.each_with_index do |version_from_set, index|
  ...
  version_name = version_from_set['version_name']
  new_version = Version.new
  new_version.name = version_name
  new_version.save
  ...
end

Error:

ActiveRecord::NotNullViolation (Mysql2::Error: Field 'created_at' doesn't have a default value: INSERT INTO versions (updated_at) VALUES ('2020-02-25 10:55:50')) We are thinking about upgrading mysql - but not convinced that this is the issue. And it's not easy to upgrade it in AWS Elastic Beanstalk Schema.db

Its working fine with RACK_ENV=development but error appear in RACK_ENV=production.

Error with stack of requests: enter image description here

  1. Error
  2. Requests should be the same but every request was cut of of one parameter and in the last request there are only one parameter.

This is how it looks in development mode. All parameters was provided:

enter image description here

We desperate. We spend couple weeks trying to track this error. Any suggestions?

Model Version:

class Version < ApplicationRecord
  include ResourceAccess
  include HtmlToPlainText

  has_many :users
  has_many :content_items
  belongs_to :mailing
  has_one :campaign, through: :mailing
  has_and_belongs_to_many :users
  has_and_belongs_to_many :teams

  validates :name, {presence: true}
  ... (here only methods)
end

标签: mysqlruby-on-rails

解决方案


推荐阅读