Rake db:迁移mysql错误

时间:2014-06-23 12:51:03

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

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

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

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

Rails 3.0.3相当陈旧。最新的3.x分支是3.2.18或更新。我怀疑你可能正在使用一个更新的宝石,它的Rails版本太旧而无法使用。如果您将Gemfile作为要点发布,那么应该更容易确定哪些宝石可能存在问题。

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

更新:你添加的Gemfile只有一个无界的gem:rdoc。这个宝石似乎是使用较旧的方式集成任务,因此可能会破坏更新版本的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

希望这有帮助。