Following the railstutorial instructions here I am getting the error:
/home/devname/.rvm/gems/ruby-2.3.1/gems/activerecord-5.0.0/lib/active_record/connection_adapters/postgresql_adapter.rb:675:in `rescue in connect': FATAL: role "devname" does not exist
I also get this if I try "rails console development".
Here is my database.yml (minus comments):
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
and my gemfile:
source 'https://rubygems.org'
gem 'rails', '5.0.0'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.5'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.0'
gem 'jbuilder', '2.4.1'
group :development, :test do
gem 'sqlite3', '1.3.11'
gem 'byebug', '9.0.0', platform: :mri
end
group :development do
gem 'web-console', '3.1.1'
gem 'listen', '3.0.8'
gem 'spring', '1.7.2'
gem 'spring-watcher-listen', '2.0.0'
end
group :production do
gem 'pg', '0.18.4'
end
I am at a loss, any help much appreciated.
Try to run your app in development mode
rails server -e development
Related
Gem file:
source 'https://rubygems.org'
gem 'rails', '5.0.1'
gem 'bcrypt', '3.1.11'
gem 'puma', '3.4.0'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.0.0'
gem 'coffee-rails', '4.2.1'
gem 'jquery-rails', '4.1.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.4.1'
gem 'bootstrap-sass', '3.3.6'
gem 'unicorn'
group :development, :test do
gem 'sqlite3', '1.3.12'
gem 'byebug', '9.0.0', platform: :mri
end
group :development do
gem 'web-console', '3.1.1'
gem 'listen', '3.0.8'
gem 'spring', '1.7.2'
gem 'spring-watcher-listen', '2.0.0'
end
group :test do
gem 'rails-controller-testing', '0.1.1'
gem 'minitest-reporters', '1.1.9'
gem 'guard', '2.13.0'
gem 'guard-minitest', '2.4.4'
end
group :production do
gem 'pg', '0.18.4'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
database.yml:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
migration fails when running rake db:migrate.
tried setting the environment variable to development using RAILS_ENV=development still it fails. i am using postgres in production as heroku provides postgres.Both the gem file and database.yml is given.
Edit:
I tried cloning repo into another machine and tried it was working fine.
When you do this:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
And then this:
production:
<<: *default
database: db/production.sqlite3
Then, your adapter in production is sqlite3. See how you set it in default and then didn't set it in production?
Also, this bit:
production:
...
database: db/production.sqlite3 << right here
Seems like it's going to give you heart ache.
You realize, naturally, that it is not recommended to use sqlite in development and postgresql in production. It says so right on the Heroku web site. Because, well, you're going to have exactly the sorts of nightmares you're having right now. (There are more technical explanations on the Heroku site and around the Innerwebs. Read them. It's good for the soul.)
Unless you like that sort of thing.
* EDIT *
Sorry, I was moving too fast. It looks like you're having the problem locally when running rake db:migrate?
In any case, still not a great idea to use different DBs in development and production.
Try setting the database config for development explicitly. Looks like the database.yml is not aligned correctly.
production:
adapter: postgresql
encoding: utf8
database: your_db
host: 127.0.0.1
pool: 5
username: your_db_username
password: your_db_password
My gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.8'
gem 'bootstrap-sass', '~> 3.3.7'
gem 'font-awesome-rails'
gem 'sqlite3'
gem 'mysql2'
gem 'sass-rails', '~> 5.0.4'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'
group :doc do
gem 'sdoc', require: false
end
my database config:
default: &default
adapter: mysql2
pool: 25
timeout: 5000
encoding: utf8
development:
<<: *default
host: 127.0.0.1
database: asteriskcdrdb
username: root
password: pwd3lfga
port: 13306
In console I have this error after I launch the console and try to read from a table inside db:
Mysql2::Error: Malformed packet
from /Users/michele/.rvm/gems/ruby-2.2.2/gems/mysql2-0.4.6/lib/mysql2/client.rb:89:in `connect'
from /Users/michele/.rvm/gems/ruby-2.2.2/gems/mysql2-0.4.6/lib/mysql2/client.rb:89:in `initialize'
from /Users/michele/.rvm/gems/ruby-2.2.2/gems/activerecord-4.2.8/lib/active_record/connection_adapters/mysql2_adapter.rb:18:in `new'
I've got a Rails app which currently uses sqlite in development and postgresql in production on Heroku. However, I'm trying to change this so that I use postgresql in development.
My Gemfile currently looks like this:
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt', '3.1.7'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'jquery-ui-rails', '~> 4.2.1'
gem 'turbolinks', '2.3.0'
gem 'jquery-turbolinks'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
gem 'chart-js-rails'
gem 'gon'
gem 'lodash-rails'
group :development, :test do
#gem 'sqlite3', '1.3.9'
gem 'pg', '0.17.1'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '3.1.0'
end
So in the development group I've replaced the 'sqlite3' gem with the 'pg' gem.
I've modified the database.yml to look something like this:
default: &default
adapter: postgresql
host: localhost
pool: 5
timeout: 5000
development:
<<: *default
database: abc_development
username: abc
password: password1
test:
<<: *default
database: abc_test
username: abc
password: password1
production:
<<: *default
database: abc_production
username: abc
password: password1
I've executed bundle install --without production however, when I try bundle exec rake db:create db:migrate I receive the following error:
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
As far I see Rails is right: you specified the pg gem only in group production, but you said you want to use it also in development.
So just move it from the production group to the beginning of your Gemfile
please help solve the problem.
I made a website. I use sqlite3.
database.yml:
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
gemfile:
source 'https://rubygems.org'
gem 'rails', '4.2.1'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc
gem 'bootstrap-sass', '3.2.0.0'
gem 'bcrypt', '~> 3.1.7'
gem 'populate'
gem 'faker'
gem 'russian', '~> 0.6.0'
gem 'will_paginate'
gem 'paperclip'
gem 'fancybox2-rails', '~> 0.2.8'
gem 'rspec-rails'
gem 'factory_girl'
gem 'database_cleaner'
group :development do
gem 'sqlite3'
end
group :production do
gem 'pg'
gem 'rails_12factor'
end
group :development, :test do
gem 'byebug'
gem 'web-console', '~> 2.0'
gem 'spring'
end
on the local server it is running. I uploaded it to heroku. as a result of getting the following error message:
500 internal server error
heroku uses postgresql. that's the problem. please help set up configuration
It is as it says: You need to add pg gem. Include the following line in your Gemfile
gem 'pg', group: :production
And you in your config/database.yml file, you can write the following code with appropriate modifications:
development:
adapter: postgresql
encoding: unicode
database: myapp_development
pool: 5
username: myapp
password: password1
test:
adapter: postgresql
encoding: unicode
database: myapp_test
pool: 5
username: myapp
password: password1
production:
adapter: postgresql
encoding: unicode
database: myapp_prouduction
pool: 5
username: myapp
password: password1
I have been going through the Rails tutorial, https://www.railstutorial.org/book/static_pages, and the first two chapters went fine. I installed Rails on my Laptop made a hello world app and a toy with the scaffold generator. There were some things I had to do differently because I am doing everything locally instead of on a cloud environment and because I am using Windows 7, but I got everything to work.
When I tried running a local server and going to my http://localhost:3000/static_pages/home page, i got the error in the Title. The following is the full error message:
Could not load 'active_record/connection_adapters/sqlite3_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
I figure it must be something with the Gemfile because that was the only difference between this and my other apps, I'm just not sure what to change. I included the Gemfile and the database.yml. Thanks in advance.
#Gemfile - sample_app
source 'https://rubygems.org'
gem 'rails', '4.2.2'
gem 'bcrypt-ruby', :require => 'bcrypt'
gem 'faker', '1.4.2'
gem 'carrierwave', '0.10.0'
gem 'mini_magick', '3.8.0'
gem 'fog', '1.23.0'
gem 'will_paginate', '3.0.7'
gem 'bootstrap-will_paginate', '0.0.10'
gem 'bootstrap-sass', '3.2.0.0'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
gem 'sqlite3'
# Access an IRB console on exception pages or by using <%= console %> in views
gem 'web-console', '~> 2.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
gem 'puma', '2.11.1'
end
Database.yml
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: 5
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
production:
<<: *default
database: db/production.sqlite3
In your Gemfile, you specify sqlite3 (the 'sqlite3' gem) for development and testing, and postgres (the 'pg' gem) for production.
But in your database.yml, you've specified the production database as sqlite3:
<database.yml>
...
production:
<<: *default
database: db/production.sqlite3
which will try to use the default adapter (sqlite3) and will look for a database file with .sqlite3 as the file extension.
You need to change your database.yml so that it uses a postgres database:
production:
adapter: postgresql
encoding: unicode
pool: 5
database: db/production
(Make sure you have postgres running on your machine either as an app or as a service.)
Or you can change your Gemfile so that you use SQLite3 for production, too.
If you tried to run the production version on your Windows machine but perhaps were running a development or test version on your OSX machine, this could be the problem.