development mode 用的是 sqlite3, production mode 用的是 mysql, 运行下面命令时出现 Illegal mix of collations 错误:
$ rake db:setup RAILS_ENV="production"
错误如下:
……
-- initialize_schema_migrations_table()
-> 1.2291s
{"检测项目"=>"肥胖指数", "Category"=>"Obese", nil=>nil}
rake aborted!
ActiveRecord::StatementInvalid: Mysql2::Error: Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation '=': SELECT `traits`.* FROM `traits` WHERE `traits`.`cname` = '肥胖指数' LIMIT 1
/Users/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `query'
/Users/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:305:in `block in execute'
/Users/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.3/lib/active_record/connection_adapters/abstract_adapter.rb:473:in `block in log'
……
Google 了一下解决方法,错误仍然没有解决。如果大家也遇到过类似的,十分感谢能分享一下你的解决方案
PS, 下面是 databae.yml:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: <%= ENV["DB"]%>
pool: 5
username: <%= ENV["DBUSER"]%>
password: <%= ENV["DBPSWORD"]%>
host: localhost
socket: /Applications/MAMP/tmp/mysql/mysql.sock #TODO, change this to standard one in the server
collation: utf8_general_ci # google 搜索说需要加上这一句,不过也没有解决问题