乐者为王

Do one thing, and do it well.

sqlite3-ruby和uninitialized constant Encoding

Ruby 1.8.6 + Rails 2.3.5

创建项目后在运行rake db:migrate时出现了以下错误:

1
2
3
4
5
6
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
rake aborted!
uninitialized constant Encoding

具体错误信息如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
/active_support/dependencies.rb:443:in 'load_missing_constant'
/active_support/dependencies.rb:80:in 'const_missing'
/active_support/dependencies.rb:92:in 'const_missing'
/sqlite3-0.0.8/lib/sqlite3/encoding.rb:9:in 'find'
/sqlite3-0.0.8/lib/sqlite3/database.rb:66:in 'initialize'
/active_record/connection_adapters/sqlite3_adapter.rb:13:in 'new'
/active_record/connection_adapters/sqlite3_adapter.rb:13:in 'sqlite3_connection'
/active_record/connection_adapters/abstract/connection_pool.rb:223:in 'send'
/active_record/connection_adapters/abstract/connection_pool.rb:223:in 'new_connection'
/active_record/connection_adapters/abstract/connection_pool.rb:245:in 'checkout_new_connection'
/active_record/connection_adapters/abstract/connection_pool.rb:188:in 'checkout'
/active_record/connection_adapters/abstract/connection_pool.rb:184:in 'loop'
/active_record/connection_adapters/abstract/connection_pool.rb:184:in 'checkout'

http://stackoverflow.com/questions/1797199/uninitialized-constant-encoding-with-sqlite3-ruby-on-windows 查到原因说是因为安装了非sqlite3-ruby包所导致。记起安装SQLite时使用的命令是gem install sqlite3,而实际上sqlite3包仅是针对ruby 1.9版本,在1.8.6上需要使用sqlite3-ruby包。用gem list查看发现果然安装的是sqlite3包。gem uninstall sqlite3把它卸载掉,然后装上sqlite3-ruby包,再次运行rake db:migrate,可以了,不再出现错误信息了。

Comments