Suraj
Suraj

Reputation: 2563

sqlite issue with heroku

I was using sqlite gem for my rails project, and since I had to put the app on Heroku, and Heroku doesn't support sqlite, I added pg gem to my Gemfile.

 gem 'pg', '0.17.1'

But now I am not able to run the project locally on my machine.

Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

I am getting this.

Please help.

Upvotes: 0

Views: 95

Answers (3)

Pavan
Pavan

Reputation: 33542

Specified 'sqlite3' for database adapter, but the gem is not loaded. Add gem 'sqlite3' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).

Add gem 'sqlite3', group: :development to your Gemfile and do bundle install.

And also you should be putting pg gem in a production group like this for you to avoid further conflicts in local

#Gemfile
group :production do
  gem 'pg', '0.17.1'
end

OR

gem 'pg', '0.17.1', group: :production

AND

gem 'sqlite3', group: :development

Update #1

And also, you should edit your database.yml to specify different adapters for development and production like this

#database.yml
development:
  adapter: sqlite3
  database: your_db
  username: your_username
  password: your_pass
  -----
  -----

production:
  adapter: postgresql
  database: your_production_db
  username: your_production_username
  password: your_production_pass
  ------
  ------

Update #2

FATAL: Peer authentication failed for user "postgres"

If you set a password based authentication, then you need to do below steps

1.Open the file pg_hba.conf for Ubuntu it will be in /etc/postgresql/9.x/main and change the this line:

local   all             postgres                                peer

to

local   all             postgres                                md5

2.Restart the server

sudo service postgresql restart

3.Login into psql and set your password

psql -U postgres

ALTER USER postgres with password 'your-pass'; #as in your database.yml

Upvotes: 3

Roshan
Roshan

Reputation: 915

Replace the gem 'sqlite' with gem 'pg' in your gemfile.

delete your Gemfile.lock and run bundle update

then, paste the following in your config/database.yml

development:
  adapter: postgresql
  encoding: unicode
  database: nameofyourapp_development
  pool: 5
  username: username
  password: password

test:
  adapter: postgresql
  encoding: unicode
  database: discuss_test
  pool: 5
  username: username
  password: password

replace the username and password as per your configuration. For mine, username is postgres and password 1234.

Heroku does not need you to define production settings in the database.yml. It will be auto configured once you push your app.

If you are getting FATAL: Peer authentication failed for user "postgres"

The problem is in your /etc/postgresql/9.3/main/pg_hba.conf file. This line:

local   all             postgres                                peer

Should be

local   all             postgres                                md5

You'll need to reload your postgresql service after changing this /etc/init.d/postgresql reload

Upvotes: 0

RailsNewbie
RailsNewbie

Reputation: 155

In your database.yml, change adapter: sqlite3 to adapter: postgresql

Upvotes: 0

Related Questions