mysql - rake 数据库 :migrate mysql error

标签 mysql ruby-on-rails ruby-on-rails-3 rake

我是 ROR 新手。我只是按照 tutorials point 上的教程进行操作。我已经安装了以下 gem:

abstract (1.0.0)  
actionmailer (3.0.3)  
actionpack (3.0.3)  
activemodel (3.0.3)  
activerecord (3.0.3)  
activerecord-mysql-adapter-flags (0.0.3)  
activerecord-ruby_mysql-adapter (0.1)  
activeresource (3.0.3)  
activesupport (3.0.3)  
arel (2.0.6)  
bigdecimal (1.1.0)  
builder (2.1.2)  
bundler (1.3.5)  
erubis (2.6.6)  
i18n (0.4.2)  
io-console (0.3)  
json (1.5.5)  
mail (2.2.14)  
mime-types (1.16)  
minitest (2.5.1)  
mysql (2.8.1 x86-mingw32)  
polyglot (0.3.1)  
rack (1.2.1)  
rack-mount (0.6.13)  
rack-test (0.5.6)  
rails (3.0.3)  
railties (3.0.3)  
rake (0.9.2.2)  
rdoc (3.9.5)   
thor (0.14.6)  
treetop (1.4.9)  
tzinfo (0.3.23)  

当我尝试运行rake db:create时,它给了我以下警告,但仍然创建了数据库。

F:\Rails Applications\Library>rake db:create
WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/tas
k' (in RDoc 2.4.2+)' instead.
    at C:/Ruby193/lib/ruby/1.9.1/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Library::Application#task called at C:/Ruby193/lib/ruby/gems
/1.9.1/gems/railties-3.0.3/lib/rails/application.rb:214:in `initialize_tasks'

在长输出的末尾它说:

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html


This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

但是它在mysql中创建了名为library_development和library_testing的数据库。

现在,当我运行 rake db:migrate 时,它​​会显示以下内容:

 F:\Rails Applications\Library>rake db:migrate
WARNING: 'require 'rake/rdoctask'' is deprecated.  Please use 'require 'rdoc/tas
k' (in RDoc 2.4.2+)' instead.
    at C:/Ruby193/lib/ruby/1.9.1/rake/rdoctask.rb
WARNING: Global access to Rake DSL methods is deprecated.  Please include
    ...  Rake::DSL into classes and modules which use the Rake DSL methods.
WARNING: DSL method Library::Application#task called at C:/Ruby193/lib/ruby/gems
/1.9.1/gems/railties-3.0.3/lib/rails/application.rb:214:in `initialize_tasks'
rake aborted!
Mysql::Error: query: not connected: CREATE TABLE `schema_migrations` (`version`
varchar(255) NOT NULL) ENGINE=InnoDB

gemfile 看起来像这样

source 'http://rubygems.org'

gem 'rails', '3.0.3'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

#gem 'sqlite3-ruby', :require => 'sqlite3'
gem 'mysql', '~>2.8.1'
gem 'activerecord-ruby_mysql-adapter', '~>0.1' 
gem 'rdoc'
# Use unicorn as the web server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
# gem 'ruby-debug'
# gem 'ruby-debug19'

# Bundle the extra gems:
# gem 'bj'
# gem 'nokogiri'
# gem 'sqlite3-ruby', :require => 'sqlite3'
# gem 'aws-s3', :require => 'aws/s3'

# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
#   gem 'webrat'
# end

谁能帮帮我吗???

最佳答案

Rails 3.0.3 相当旧了。最新的 3.x 分支为 3.2.18 或更高版本。我怀疑您可能正在使用较新的 gem,其 Rails 版本太旧而无法运行。如果您将 Gemfile 作为要点发布,应该更容易确定哪些 gem 可能有问题。

通常在这种情况下,无限制的 Gem,即那些在 Gemfile 中没有设置显式版本的 Gem,将尝试使用比 Rails 版本可以支持的更新版本的 Gem,并且会破坏应用程序。

更新:您添加的 Gemfile 只有一个无界 gem:rdoc。这个 gem 似乎使用了一种旧的集成任务的方式,因此可能会与新版本的 rake 发生冲突。我们将调整 rake 的版本和 rdoc 的版本,以匹配 Rails 3.0.3 的发布时间段。

version of rdoc发布时间最接近rails 3.0.3是 3.0.1。更改您的 Gemfile,而不是

gem 'rdoc'

它说

gem 'rdoc', '~> 3.0.1'

接下来,运行以下命令来安装 closest version of rake到 Rails 3.0.3

gem uninstall rake --version 0.9.2.2
gem install rake --version 0.8.7

现在,运行bundler来安装您要求的rdoc版本:

bundle install

最后使用 bundler 使用您要求在 Gemfile 中使用的特定版本的 gem 来执行 rake 命令:

bundle exec rake db:create
bundle exec rake db:migrate

如果这不能解决问题,您可以随时强制使用您想要使用的特定版本的 rake,如下所示:

bundle exec rake _0.8.7_ db:create

希望这有帮助。

关于mysql - rake 数据库 :migrate mysql error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24366433/

相关文章:

ruby-on-rails - Rails 回形针图像 URL 上传不起作用

php - 使用 MYSQL 选择日期之间的行?

ruby-on-rails - 不会为Rails固定装置执行Postgresql触发器

JavaScript 未加载最新提交的数据

ruby-on-rails - Docker容器中的Rails应用程序不会在开发中重新加载

ruby-on-rails - 链接到 ruby​​-on-rails 中的另一个页面

ruby-on-rails-3 - 将 redcarpet gem 添加到 Rails 应用程序后运行 "sh: make: command not found"时出现 "$ bundle"

php - 根据文件扩展名和带超链接的文件数显示从 MySQL 上传的文件

mysql - MySQL 的“自然排序”?

MySQL查询以选择字段中的第一个单词并返回计数