mysql - 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
- 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:
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
解决方案
推荐阅读
- c# - 在不同项目中创建时,EntityFramework 上下文不会检索任何数据
- reactjs - 选择输入和重构最佳实践时的奇怪行为
- python - Python字符串到字典
- c# - DateTime 比较(介于)日期与日月年时分秒
- biztalk - 如何提取姓氏?
- reactjs - React 事件不会在移动设备上触发,但在桌面上可以正常工作。我试过onClick,onTouchStart,onTouchEnd,onMouseUp,OnMouseDown
- java - 使用 jfugue,如何从数组中生成随机音乐字符串(使用 player.play)?
- arrays - Python:随机播放并放回numpy数组的初始顺序元素
- go - 如何保证结构字段的存在,如接口对方法所做的?
- javascript - 在不同的刀片中显示查询结果