I am using Rails 3.2.2 on Ruby 1.8.7 with mysql2 0.3.11 (against a mysql 14.14 server), and sometimes a created_at
or updated_at
value will be an invalid DateTime, and cause my app to throw an exception with the message "Invalid date: 2022-03-00 00:00:00"
.
I am not explicitly creating, setting, reading, or doing anything with the created_at
and updated_at
columns.
Inspecting the table through a mysql
client, for the most part, the value in each of these columns is "0000-00-00 00:00:00
", which ends up as nil
in Rails. However, several rows show values such as "2022-03-00 00:00:00
" (they are all different, though as far as I can tell, all in 2022).
Interestingly, I can't even run .destroy()
from Rails, because it can't create the object.
What could be setting invalid dates for those columns?
Edit: This is happening for all tables. Here is my schema.rb, and all of the migrations for one of the tables: https://gist.github.com/2930655
Edit2: I solved it myself (see my answer below), but would appreciate if you'd weigh in on if it's a bug, and if so, which package the bug is with (ActiveRecord?).