Mysql “Time” type gives an “ArgumentError: argument out of range” in Rails if over 24 hours

后端 未结 1 1758
-上瘾入骨i
-上瘾入骨i 2021-01-16 06:31

I\'m writing a rails application on top of a legacy mysql db which also feeds a PHP production tool. Because of this setup so its not possible for me to change the databases

1条回答
  •  别那么骄傲
    2021-01-16 07:17

    I'm not familiar with Rails so there can be a clean, native solution to this, but if all else fails, one workaround might be writing into a VARCHAR field, then running a 2nd query to copy it over into a TIME field within mySQL:

    INSERT INTO tablename (name, stringfield) 
    VALUES ("My Record", "999:02:02");
    
    UPDATE tablename SET datefield = CAST(stringfield as TIME) 
    WHERE id = LAST_INSERT_ID();
    

    0 讨论(0)
提交回复
热议问题