简体   繁体   English

耙db:迁移mysql错误

[英]Rake db:migrate mysql error

I am new to ROR. 我是ROR的新手。 I was just following the tutorials at tutorials point . 我只是在教程点关注这些教程。 I have installed following gems: 我已经安装了以下宝石:

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)  

When I tried to run rake db:create it gave me following warnings, but still created the databases. 当我尝试运行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'

and at the end of long output it said: 在长输出的末尾说:

[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.

But it has created the databases named library_development and library_testing in mysql. 但是它已经在mysql中创建了名为library_development和library_testing的数据库。

Now when I run rake db:migrate it says the following: 现在,当我运行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

the gemfile looks like this 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

Can anyone please help me??? 谁能帮帮我吗???

Rails 3.0.3 is fairly old. Rails 3.0.3相当老。 The latest 3.x branch is at 3.2.18 or newer. 最新的3.x分支是3.2.18或更高版本。 I suspect you might be using a newer gem with a version of Rails that's too old for it to function with. 我怀疑您可能正在使用带有Rails版本的较新的gem,而该版本太旧而无法使用。 If you post your Gemfile as a gist it should be easier to determine which gems could possibly be problematic. 如果您将Gemfile作为要点发布,则应该更容易确定哪些宝石可能有问题。

Typically in such a case unbounded gems ie those without an explicit version set in the Gemfile will attempt to use a newer version of the Gem than the version of Rails can support and will break the app. 通常,在这种情况下,无边界的宝石,即那些没有在Gemfile中设置显式版本的宝石,将尝试使用比Rails所能支持的版本更新的Gem,并将破坏应用程序。

Update: The Gemfile you added only has a single unbounded gem: rdoc. 更新:您添加的Gemfile仅具有一个不受限制的gem:rdoc。 This gem seems to be using an older way of integrating tasks and so might be breaking with a newer version of rake. 这个gem似乎正在使用一种较旧的方式来集成任务,因此可能会被较新版本的rake破坏。 We'll adjust both the versions of rake and the version of rdoc to match the time period that rails 3.0.3 came from. 我们将调整rake的版本和rdoc的版本,以匹配rails 3.0.3的生成时间段。

The version of rdoc that was released closest to rails 3.0.3 is 3.0.1. 最接近rails 3.0.3发行的rdoc版本是3.0.1。 Change your Gemfile so instead of 更改您的Gemfile,而不是

gem 'rdoc'

it says 它说

gem 'rdoc', '~> 3.0.1'

Next, run the following commands to install the closest version of rake to rails 3.0.3 接下来,运行以下命令以将最接近rake的版本安装到rails 3.0.3

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

Now, run bundler to install the version of rdoc you've asked for: 现在,运行捆绑程序以安装您要求的rdoc版本:

bundle install

And finally use bundler to execute your rake command using the specific versions of the gems you've asked to use in the Gemfile: 最后使用bundler使用您要求在Gemfile中使用的gem的特定版本执行rake命令:

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

If that doesn't solve it, you can always force using the specific version of rake you want to use like so: 如果仍不能解决问题,则可以始终强制使用要使用的特定版本的rake,如下所示:

bundle exec rake _0.8.7_ db:create

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM