I've built a Rails 3 application on my dev machine, and am ready to deploy. I've setup the app on the production machine, and everything is running smoothly. I've used yaml_db
to dump the data from the database on the development machine, and am trying to load that into the database on the production box with rake db:data:load RAILS_ENV=production
. This is the output I get (with --trace
enabled):
** Invoke db:load (first_time)
** Invoke db:schema:load (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:schema:load
-- create_table("albums", {:force=>true})
-> 0.1097s
-- create_table("composers", {:force=>true})
-> 0.0111s
-- create_table("tracks", {:force=>true})
-> 0.0123s
-- create_table("user_sessions", {:force=>true})
-> 0.0079s
-- create_table("users", {:force=>true})
-> 0.1218s
-- initialize_schema_migrations_table()
-> 0.0160s
-- assume_migrated_upto_version(20110331123206, "db/migrate")
-> 0.1078s
** Invoke db:data:load (first_time)
** Invoke environment
** Execute db:data:load
rake aborted!
incompatible character encodings: ASCII-8BIT and UTF-8
/usr/local/lib/ruby/gems/1.9.1/ge开发者_开发知识库ms/yaml_db-0.2.0/lib/serialization_helper.rb:86:in `join'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:86:in `block in load_records'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:85:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:85:in `load_records'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:74:in `load_table'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/yaml_db.rb:62:in `block (2 levels) in load_documents'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/yaml_db.rb:60:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/yaml_db.rb:60:in `block in load_documents'
/usr/local/lib/ruby/1.9.1/syck.rb:235:in `call'
/usr/local/lib/ruby/1.9.1/syck.rb:235:in `load_documents'
/usr/local/lib/ruby/1.9.1/syck.rb:235:in `load_documents'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/yaml_db.rb:59:in `load_documents'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:57:in `block in load'
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.0.5/lib/active_record/connection_adapters/abstract/database_statements.rb:139:in `transaction'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:56:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/serialization_helper.rb:31:in `load'
/usr/local/lib/ruby/gems/1.9.1/gems/yaml_db-0.2.0/lib/tasks/yaml_db_tasks.rake:35:in `block (3 levels) in <top (required)>'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `call'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:636:in `block in execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:631:in `execute'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:597:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:607:in `block in invoke_prerequisites'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:604:in `invoke_prerequisites'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:596:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:590:in `invoke_with_call_chain'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:583:in `invoke'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2051:in `invoke_task'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block (2 levels) in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `each'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2029:in `block in top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2023:in `top_level'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2001:in `block in run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:2068:in `standard_exception_handling'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/lib/rake.rb:1998:in `run'
/usr/local/lib/ruby/gems/1.9.1/gems/rake-0.8.7/bin/rake:31:in `<top (required)>'
/usr/local/bin/rake:19:in `load'
/usr/local/bin/rake:19:in `<main>'
I've found about a million and one hits from other people with the same error (incompatible character encodings ASCII-8BIT and UTF-8
), but most of them are trying to render UTF-8 encoded strings in views, etc. Does anyone have any idea what's happening?
EDIT: Here's the line/block in question from serialization_helper.rb
:
records.each do |record|
quoted_values = record.zip(columns).map{|c| ActiveRecord::Base.connection.quote(c.first, c.last)}.join(',')
ActiveRecord::Base.connection.execute("INSERT INTO #{quoted_table_name} (#{quoted_column_names}) VALUES (#{quoted_values})")
end
Maybe there's a quick way to hack that up with force_encoding()
or otherwise? I'd try, but my Ruby fu just ain't that strong.
I never sorted this out and I'd really rather not accept this workaround as the answer, but when no one else has anything to offer, c'est la vie. As a workaround, and because I was loading the entire database, I just moved production.sqlite
from the development box to the production box. This doesn't feel quite right to me, but maybe I'm just paranoid. Either way, it worked and everything's running smoothly now.
精彩评论