【问题标题】:Mysql gem and Rails3Mysql gem 和 Rails3
【发布时间】:2012-03-24 21:15:14
【问题描述】:

我正在尝试在我的 Gemfile 中安装 mysql gem。我输入这个:

group :development, :test do

  #gem 'sqlite3-ruby', :require => 'sqlite3'

  #using mysql gem
  gem 'mysql', '2.8.1'

end

我运行 bundle install 并且一切运行正常。好的,当我运行“rake db:reset”时,我得到了这个:

Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.)

Tasks: TOP => db:drop => db:load_config
(See full trace by running task with --trace)

既然我用的是mysql,为什么还要引用sqlite3呢?

【问题讨论】:

    标签: mysql ruby-on-rails-3


    【解决方案1】:

    我建议你使用 mysql2 gem,而不是 mysql 的(参见:What the difference between mysql and mysql2 gem

    另外你需要修改“config/database.yml”文件,现在大概是这样的:

    development:
      adapter: sqlite3
      database: db/development.sqlite3
      pool: 5
      timeout: 5000
    

    这意味着 Rails 尝试使用 sqlite3 而不是 mysql 作为您的数据库。 Rails 指南中有一节介绍如何为 MySQL 更改此设置:http://guides.rubyonrails.org/getting_started.html#configuring-a-database

    【讨论】:

      【解决方案2】:

      看起来您创建了一个 rails 应用程序,但没有指定您将使用 MySql 数据库。只是一个想法......

      你跑了吗

      rails new APP_NAME -d mysql -- This will create the app configured to use MySQL
      

      rails new APP_NAME -- 这将创建配置为使用 SQLLite3 的应用程序

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-25
        • 1970-01-01
        • 2012-01-17
        • 2011-05-18
        相关资源
        最近更新 更多