Rails 3.1 pre迁移问题

时间:2011-05-17 09:19:29

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

现在我将rails 3.0.7升级到rails 3.1 pre版本。当我创建一个示例项目时,它工作正常。创建一个脚手架后,我尝试迁移,但它让我的耙子中止了!消息。

这是我的代码

rails g scaffold product name:string price:decimal category:string
      invoke  active_record
      create    db/migrate/20110517090853_create_products.rb
      create    app/models/product.rb
      invoke    test_unit
      create      test/unit/product_test.rb
      create      test/fixtures/products.yml
       route  resources :products
      invoke  scaffold_controller
      create    app/controllers/products_controller.rb
      invoke    erb
      create      app/views/products
      create      app/views/products/index.html.erb
      create      app/views/products/edit.html.erb
      create      app/views/products/show.html.erb
      create      app/views/products/new.html.erb
      create      app/views/products/_form.html.erb
      invoke    test_unit
      create      test/functional/products_controller_test.rb
      invoke    helper
      create      app/helpers/products_helper.rb
      invoke      test_unit
      create        test/unit/helpers/products_helper_test.rb
      create  app/assets/stylesheets/scaffold.css.scss
      invoke  assets
      create    app/assets/javascripts/products.js.coffee
      create    app/assets/stylesheets/products.css.scss
rake db:migrate
==  CreateProducts: migrating =================================================
-- create_table(:products)
   -> 0.0053s
==  CreateProducts: migrated (0.0054s) ========================================

rake aborted!
An error has occurred, all later migrations canceled:

undefined method `rows' for nil:NilClass

(See full trace by running task with --trace)

我正在使用ruby 1.9.2和xampp。

任何人都可以知道这是什么问题吗?

3 个答案:

答案 0 :(得分:6)

我使用mysql2 v0.2.6作为数据库适配器时遇到了同样的问题 我试图解决它更新mysql2到最新版本0.3.2,但我无法在Windows上编译此gem。 但我仍然认为最新版本的mysql2可能有效。 目前我使用“pg”gem作为DB的postgres适配器,它可以与Rails 3.1.pre

一起使用

答案 1 :(得分:3)

这对我有用。我更改了Gemfile以使用github repo:

gem 'mysql2', :git => 'git://github.com/brianmario/mysql2.git'

然后运行捆绑安装。关于libmysqlclient.18.dylib丢失之后我仍然遇到错误,我通过运行修复了(你的路径可能会有所不同):

install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p180/bundler/gems/mysql2-a1ddafaf8b31/lib/mysql2/mysql2.bundle

答案 2 :(得分:0)

我刚刚在Windows 7计算机上遇到此问题,并且能够解决它,感谢http://rorguide.blogspot.com/2011/03/installing-mysql2-gem-on-ruby-192-and.html。我已经安装了devkit,这就是为我做的:

gem install mysql2 -- '--with-mysql-lib="c:\Program Files\MySQL\MySQL Server 5.1\lib\opt" --with-mysql-include="c:\Program Files\MySQL\MySQL Server 5.1\include"'

这个安装了0.3.7版本的MySQL适配器,我能够成功运行我的迁移。