在Rails4中将我的数据库从sqlite3切换到mysql时出现strftime错误
作者:互联网
最近我将我的数据库从sqlite3更改为mysql.当我运行我的项目时,我在其中一个使用此查询的文件中收到此错误.
date = Date.today 1
@employees = Employee.where(“status =?AND strftime(‘%d /%m’,date_of_birth)=?”,“Active”,date.strftime(‘%d /%m’)
ActionView::Template::Error (Mysql2::Error: FUNCTION hrms_development.strftime does not exist: SELECT COUNT(*) FROM `employees` WHERE (status = 'Active' AND strftime('%d/%m', date_of_birth) = '28/03')):
210:
211: <% date = Date.today %>
212: <% @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')) %>
213: <% if @employees.empty? %>
214:
215: <%else%>
216: <% @employees.each do |e| %>
app/views/home/_group_admin.html.erb:213:in `_app_views_home__group_admin_html_erb___2522183600721478262_91627100'
app/views/home/index.html.erb:17:in `_app_views_home_index_html_erb__2772204906267359422_86967120'
ActionView::Template::Error: Mysql2::Error: FUNCTION hrms_development.strftime does not exist: SELECT COUNT(*) FROM `employees` WHERE (status = 'Active' AND strftime('%d/%m', date_of_birth) = '28/03')
解决方法:
只需更换即可试用
<% @employees = Employee.where("status = ? AND strftime('%d/%m', date_of_birth) = ?", "Active" , date.strftime('%d/%m')) %>
同
<% @employees = Employee.where("status = ? AND DATE_FORMAT(date_of_birth,'%d/%m') = ?", "Active" , date.strftime('%d/%m')) %>
标签:mysql,sqlite,ruby-on-rails-4 来源: https://codeday.me/bug/20190928/1826210.html