Test data does not load into mysql
Posted: 02 February 2010 12:43 PM   [ Ignore ]
Newbie
Rank
Total Posts:  8
Joined  2010-02-02

Hi, when I’m trying to rake db:load:fixtures, I get

Mysql::Error: Incorrect datetime value: ‘2010-02-02 16:20:25 UTC’ for column ‘last_online_time’ at row 1:
INSERT INTO `devices` (`name`, `updated_at`, `icon_id`, `provision_status_id`, `account_id`, `last_online_time`, `group_id`, `id`, `recent_reading_id`, `imei`, `profile_id`, `created_at`)
VALUES (‘device 3’, ‘2010-02-02 18:20:25’, 3, 1, 1, ‘2010-02-02 16:20:25 UTC’, 2, 3, 3, 54321, 1, ‘2010-02-02 18:20:25 UTC’)

I’m using mysql. If I strip off the ‘UTC’ part and paste the sql it works fine. Any hints how to either make mysql recognize ‘UTC’?

This is the fixture:


device3:
id: 3
name: device 3
imei: 54321
created_at: <%= Time.zone.now.to_s %>
recent_reading_id: 3
provision_status_id: 1
account_id: 1 # Nick Co
group_id: 2
last_online_time: <%= (Time.zone.now-120*60).to_s %>
icon_id: 3
profile_id: 1

Thanks

Jan

Profile
 
 
Posted: 03 February 2010 09:44 AM   [ Ignore ]   [ # 1 ]
Administrator
RankRankRankRank
Total Posts:  249
Joined  2008-12-18

What version of MySQL are you using?

Profile
 
 
Posted: 03 February 2010 10:10 AM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  8
Joined  2010-02-02

I use mysql 5.1 on windows for development.

I did change
<%= (Time.zone.now-120*60).to_s %>

to

<%= (Time.now-120*60).to_s :db%>

which solved the problem. Since it’s just test data, I’m hoping that this will not have any impact on the tests

Profile
 
 
Posted: 03 February 2010 10:50 AM   [ Ignore ]   [ # 3 ]
Administrator
RankRankRankRank
Total Posts:  249
Joined  2008-12-18

Good call. This doc shows different date formats and their representation (including :db)

http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Conversions.html#M000569

Profile
 
 
   
 
 
‹‹ Statistics?      load paths error in newrelic ››