2009/10/16

[rails] Mysql で Incorrect datetime value が発生

Rails 2.3.4 と Mysql 5.0 (Windows) の環境で、Unit Test を実行すると下記のエラーが発生。

>rake test:units
  1) Error:
test_should_authenticate_user(UserTest):
ActiveRecord::StatementInvalid: Mysql::Error: Incorrect datetime value: '2009-10-16 07:56:13 UTC' for column 'remember_token_expires_at' at row 1: INSERT INTO `users` (`salt`, `updated_at`, `crypted_password`, `remember_token_expires_at`, `id`, `remember_token`, `login`, `created_at`, `email`) VALUES ('356a192b7913b04c54574d18c28d46e6395428ab', '2009-10-15 07:56:13', '39e3509c8a1dff4e5b35850d970992321c4f1358', '2009-10-16 07:56:13 UTC', 1, '77de68daecd823babbb58edb1c8e14d7106e83bb', 'quentin', '2009-10-10 07:56:12', 'quentin@example.com')

Mysql の sql-mode を空白に設定することで解決しました。

my.ini
# Set the SQL mode to strict
#sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
sql-mode=''

参考:

Now, open the my.ini file located at c:program files/MySQL/MySQL
Server X.x/my.ini.
Add a # at the begining of the line: sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Type sql_mode='' on the next line and save the file.
restart mysql

fixed it

[Rails] Re: restful_authentication rspec failures "Mysql::Error: Incorre

0 件のコメント: