Ruby on Rails error: Invalid connection "adapter" - ruby-on-rails

I'm using Ruby on Rails ( rails version 2.3.4), and using pg gem (version 0.12.2) on Windows.
My database.yml file has the following content:
production:
adapter: postgresql
encoding: utf8
host: localhost
database: canvas4
username: canvas
password: canvas
port: 5433
timeout: 5000
pool: 5
queue:
adapter: postgresql
encoding: utf8
database: canvas4_queue
host: localhost
port: 5433
username: canvas
password: canvas
timeout: 5000
pool: 5
But when i run command: bundle exec rake db:initial_setup RAILS_ENV=production, the error occurs:
Invalid connection "adapter"
I've also tried with gem "activerecord-postgresql-adapter" but the same error occurs as above.
I can successfully setup with sqlite3 driver.
Do you know how to get postgresql adapter to work with rails 2.3 ?

make sure your db-adapter in database.yml is set to "postgresql". If still you have the same problem, then try using the pure-ruby adapter:
gem install postgres-pr
(make sure you uninstall the pg gem before... to avoid conflicts)
If it works, then it's a problem with the postgres gem. Anyway, for development purposes, using the pure-ruby gem is usually ok.

Related

ActiveRecord::AdapterNotFound: database configuration specifies nonexistent mysql adapter

I'm facing this mysql adapter error while trying to run the application in the production mode.. Also encountered this while precompiling assets.
ActiveRecord::AdapterNotFound: database configuration specifies nonexistent mysql adapter
database.yml
development:
adapter: mysql2
encoding: utf8
host: localhost
database: staging
pool: 5
username: root
password: root
production:
adapter: mysql2
encoding: utf8
host: localhost
database: staging
pool: 5
username: root
password: root
In my Gemfile,
gem 'mysql2'
gem 'activerecord-mysql-adapter'
I've already got these gems bundled. What am I missing or working out wrong ?
Remove the following line from your Gemfile:
gem 'activerecord-mysql-adapter'
It is not needed. But the other line is correct. Then run bundle install again. I'm not sure what is causing your problem but I think it might be a problem of overlapping namespaces.
// Also you shouldn't use the same database for development and production mode.

recompiling database.yml file with gemfile? ruby on rails

I'm new to Ruby on Rails and postgreSQL and had a question. Does the database.yml file get compiled when you run bundle install on a Gemfile? Initially my gemfile had sqlite3, but I changed it to pg and tried to run bundle install again to recompile the database.yml file, but the file still says it's using SQLite.
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
I want the adapter to be switched to postgresql and I believe some other fields should be switched when using pg, but I'm unsure. Can anyone clarify this for me, thank you.
No, database.yml is not recompiled automatically. When you change the gem in Gemfile, you need to also change the file:
development:
adapter: postgresql
database: dbname
username: user
password: password
encoding: unicode
you need to replace too your the adapter value in your config/database.yml
When you run bundle install it will install the gems declared in your Gemfile, but you must manually setup you database configuration. Bundle don't compile your anything on your application except the Gemfile.lock where are declared the gems versions.
Something like:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
host: localhost
password: password # if you need a password
test:
adapter: postgresql
encoding: unicode
database: myapp_test
host: localhost
password: password # if you need a password
production:
adapter: postgresql
encoding: unicode
database: myapp_production
host: localhost
password: password # probably you will need a password

Rails using unkown config file for database connection

I have a weird problem.
I have set my database.yml file to use sqlite3 for all three (production, test, dev) databases
I create a new rails project with all defaults.
I fire up rail server using WEBrick
I get "ActiveRecord::ConnectionNotEstablished" error
I try $rake db:create
I get the following error:
specified 'postgresql' for database adapter, but the gem is not loaded. Add gem 'pg' to your Gemfile.
I install pg and postgres server and I get
fe_sendauth: no password supplied Error on the webpage
I try $rake db:create again on the console and get
fe_sendauth: no password supplied (which I know is a postgres password error)
It seems that Rails is choosing a different database adapter than in my database.yml file.
I don't know where it could be. It even seems to be looking for a specific database that I used in some previous project. Therefore Rails must be looking at someother config file.
Can someone help.
Add sqlite3 gem to your Gemfile:
gem 'sqlite3'
and set sqlite3 as adapter in your database.yml:
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000

Convert a Ruby on Rails app from sqlite to MySQL?

I made an app in Ruby on Rails and now I want to get it hosted. However, they require that I use MySQL and I set it up using sqLite3. Is there any way to convert it to use MySQL?
Step 0
To be safe, I recommend experimenting a bit with this technique in a virtual machine. Save yourself a bunch of heartache and build a virtual machine, check out your code, and have a safe playground that you can throw away if tragedy strikes.
Step 1
Make a backup copy of your database.yml file.
(from your application root)
cp config/database.yml config.database.yml.sqlite3
Step 2
Make a backup copy of your data
For Rails 3, install the YAML DB gem: https://github.com/ludicast/yaml_db
by running
gem install yaml_db
and then add to your Gemfile.
gem 'yaml_db'
For Rails 2.x install the YAML DB plugin:
script/plugin install git://github.com/adamwiggins/yaml_db.git
Run the dump task
rake db:dump
Step 3
Update your config/database.yml file. You will find entries like
development:
adapter: sqlite3
database: db/development.sqlite3
timeout: 5000
test:
adapter: sqlite3
database: db/test.sqlite3
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
timeout: 5000
Change them to
development:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_development**
pool: 5
username: **root**
password: **supersecretpassword**
**socket: /opt/local/var/run/mysql5/mysqld.sock**
test:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_test**
pool: 5
username: **root**
password: **supersecretpassword**
socket: **/opt/local/var/run/mysql5/mysqld.sock**
production:
adapter: mysql
encoding: utf8
reconnect: false
database: **myapp_production**
pool: 5
username: **root**
password: **supersecretpassword**
socket: **/opt/local/var/run/mysql5/mysqld.sock**
Be sure to update the values surrounded by asterix as appropriate for your platform! The socket value is only good for Mac OSX using MacPorts. Most flavors of linux do not require this value.
Step 5
If you have some errors in the following step, you might have to install the mysql or mysql2 gem:
sudo gem install mysql
or
sudo gem install mysql2
Have rake create your database
rake db:create
rake db:schema:load
Step 6
Use YamlDb to reload your data into MySql
rake db:load
As long as you have not written any SQL statements that run in sqlLite3 and not MySQL (which you won't have if all your database access is via ActiveRecord and ActiveRecord migrations) then all you need to do is change the database adapter in your database.yml config file.
Check Taps. I've successfully converted a Mysql database to Postgres with it --it should support SQLite.
Edit: Including working link from cony's comment here.
If there's no data to migrate, simply update database.yml and run 'rake db:schema:load' in the new environment. (NOT db:migrate which should only be used for incremental migrations!)
myproject user$ cd
user $ rails new myproject -d mysql
Say 'no' for all question but for Overwrite .../myproject/config/*database.yml*? (enter "h" for help) [Ynaqdh] say 'yes'.

SQLite and Ruby on Rails on PC

I am using instant rails which makes use of SQLite and I am unable to connect to the database. I have been using a tutorial that uses MySQL and I have been unable to find instructions for SQLite. Any suggestions?
You could install sqlite.
Or, assuming you have mysql installed, you could change your config/database.yml file to use mysql instead of sqlite.
(From using rails -d mysql testapp)
development:
adapter: mysql
encoding: utf8
reconnect: false
database: awesome_development
pool: 5
username: root
password:
host: localhost
Update
To use sqlite3, you need the sqlite gem and to set up your rails database.yml to use it. The default config rails generates uses sqlite and looks like this
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
to install, here are some good looking instructions

Resources