一尘不染

在Rails4中将数据库从sqlite3切换到mysql时出现strftime错误

mysql

最近我将数据库从sqlite3更改为mysql。运行项目时,我在使用此查询的文件之一中遇到此错误。

日期= Date.today +1

@employees = Employee.where(“状态=?AND strftime(’%d
/%m’,date_of_birth)=?”,“活动”,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')

阅读 489

收藏
2020-05-17

共1个答案

一尘不染

只需替换一下即可尝试一下,

<% @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')) %>
2020-05-17