我是Ruby On Rails的新手。我一直在尝试使用 rails generate model 命令创建一个名为Book的模型,但是我收到以下错误消息:
F:\Faizul\Noah-Data\Backup\Ruby\Rails App\library>rails generate model Book
C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `require': cannot load such file -- mysql2/2.4/mysql2 (LoadError)
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2/mysql2.rb:2:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.4.10-x64-mingw32/lib/mysql2.rb:31:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:81:in `block (2 levels) in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:76:in `block in require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `each'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler/runtime.rb:65:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/bundler-1.16.1/lib/bundler.rb:114:in `require'
from F:/Faizul/Noah-Data/Backup/Ruby/Rails App/library/config/application.rb:7:in `<top (required)>'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/actions.rb:15:in `require'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/actions.rb:15:in `require_application_and_environment!'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands/generate/generate_command.rb:19:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/command.rb:27:in `run'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor/invocation.rb:126:in `invoke_command'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/thor-0.20.0/lib/thor.rb:387:in `dispatch'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command/base.rb:63:in `perform'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/command.rb:44:in `invoke'
from C:/Ruby24-x64/lib/ruby/gems/2.4.0/gems/railties-5.1.4/lib/rails/commands.rb:16:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
采取以下行动来克服这个问题,但失败了:(
default: &default adapter: mysql2 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> timeout: 5000 development: adapter: mysql2 database: library_development username: root password: root host: localhost port: 3309 test: adapter: mysql2 database: library_test username: root password: root host: localhost port: 3309 production: adapter: mysql2 database: library_production username: root password: root host: localhost port: 3309
答案 0 :(得分:0)
目前,目前还没有针对Ruby 2.4 for Windows的mysql2二进制文件。
有关详细信息,请参阅this github问题 https://github.com/brianmario/mysql2/issues/861
希望这可以帮到你。
答案 1 :(得分:0)
编译你的mysql评论为我工作 https://github.com/brianmario/mysql2/issues/923#issuecomment-361346864
但请注意第3步 而不是
cd&#34; C:\ Ruby24-x64 \ bin \ ruby&#34; extconf.rb --with-mysql-dir =&#34; C:\ Program Files \ MySQL \ MySQL Connector.C 6.1&#34;
我做了
&#34; C:\ Ruby24-64 \ BIN \红宝石&#34; extconf.rb --with-mysql-dir =&#34; C:\ Program Files (x86)\ MySQL \ MySQL Connector.C 6.1&#34;
不&#34; cd&#34;在乞讨和我的连接器在&#34; C:\ Program Files(x86)&#34;文件夹中。
也在步骤#6 我正在复制
C:\ Ruby24-64 \ lib中\红宝石\宝石\ 2.4.0 \宝石\ mysql2-0.4.10-x64的的mingw32 \分机\ mysql2 \ mysql2.so
到新创建的文件夹
C:\ Ruby24-64 \ lib中\红宝石\宝石\ 2.4.0 \宝石\ mysql2-0.4.10-x64的的mingw32 \ lib中\ mysql2 \ 2.4
编译过程显示了很多警告,但最终rake db:migrate开始为我工作,所以你的代码应该是
答案 2 :(得分:0)
请安装Mysql服务器。 安装在宝石下面。
的libmysqlclient-dev的 要么 Mysql-devl