开发者

ruby on rails converting from sqlite3 to mysql2 gem

开发者 https://www.devze.com 2023-02-17 18:26 出处:网络
My installation Ubuntu 10.10 Rails 3 gem = sqlite3 and sqlite3-ruby gem = mysql2 Now I created a application called mytestapp, using

My installation

  • Ubuntu 10.10
  • Rails 3
  • gem = sqlite3 and sqlite3-ruby
  • gem = mysql2

Now I created a application called mytestapp, using

rails new mytestapp

As usual with rails 3 it defaults to using sqlite3 database. Now I wanted to change the database for mytestapp so that it uses MySql database.

I made changes here

My new database.yml looked something like this

development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: mytestapp_development
  pool: 5
  username: mytestapp
  password: hacked
  socket: /var/run/mysqld/mysqld.sock

Now I goto localhost:3000 and click on the about application's development environment I get the following error

ActiveRecord::ConnectionNotEstablished

MySql user mytestapp has proper permissions for the database.

Infact when I create a new rails app using the following

rails new anotherapp -d mysql

It works great. What can be missing here.


Have you ran bundle install after editing your Gemfile?

If you did, then try to run the following command to see what's the difference between your hand-edited application and the new you created with -d mysql:

diff /path/to/hand-edited-app /path/to/rails-created-mysql-app
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号