The builds for my rails app are failing with the following error on running tests
9) FailedKeyChecks should contain a value
Failure/Error: ActiveRecord::Base.connection.execute(query)
ActiveRecord::NoDatabaseError:
FATAL: database "myapp_development" does not exist
10) User is invalid without name
Failure/Error: raise ActiveRecord::NoDatabaseError.new(error.message, error)
ActiveRecord::NoDatabaseError:
FATAL: database "myapp_development" does not exist
what am I doing wrong? My codeship.database.yml file
development:
adapter: postgresql
host: localhost
encoding: unicode
pool: 10
username: <%= ENV['PG_USER'] %>
template: template1
password: <%= ENV['PGPASSWORD'] %>
database: development<%= ENV['TEST_ENV_NUMBER'] %>
port: <%= ENV['DATABASE_PORT'] %>
sslmode: disable
test:
adapter: postgresql
host: localhost
encoding: unicode
pool: 10
username: <%= ENV['PG_USER'] %>
template: template1
password: <%= ENV['PGPASSWORD'] %>
database: test<%= ENV['TEST_ENV_NUMBER'] %>
port: <%= ENV['DATABASE_PORT'] %>
sslmode: disable
my setup commands
rvm use 2.4.1 --install
bundle install
cp codeship.database.yml config/database.yml
export RAILS_ENV=test
bundle exec rake db:create
#bundle exec rake db:migrate
bundle exec rake db:schema:load
and my test commands
RAILS_ENV=test bundle exec rake
RAILS_ENV=test bundle exec rspec
any idea why development database is being referenced? Thanks in advance
Try running bundle exec rake db:create:all
followed by bundle exec rake db:migrate
It might have failed because you forgot the 'all'
Related
I created a new rails project and did few configuration changes in database.yml.
Then had to create the database using the command rake db:create inorder to continue developing the application but I get the error below.
Els-MacBook-Pro:eshop el$ rake db:create
warning ../../package.json: No license field
FATAL: role "eshop" does not exist
Couldn't create 'eshop_development' database. Please check your configuration.
rake aborted!
PG::ConnectionBad: FATAL: role "eshop" does not exist
Tasks: TOP => db:create
(See full trace by running task with --trace)
Els-MacBook-Pro:eshop el$
I will also post the contents of my database.yml below:
default: &default
adapter: postgresql
encoding: unicode
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
development:
<<: *default
host: localhost
database: eshop_development
username: eshop
password: eshop
test:
<<: *default
host: localhost
database: eshop_test
username: eshop
password: eshop
production:
<<: *default
database: eshop_production
username: eshop
password: <%= ENV['ESHOP_DATABASE_PASSWORD'] %>
I will be grateful if someone can help me figure out why I cannot create a db. I have read all types of solutions and none seems to be working. Thanks.
In your database.yaml you need to add a port: 5432, and then Try rails db:create, as rake has been deprecated.
create a role in your postrgesql database named 'eshop'
i have a ruby rails app i deployed to aws with elastic beanstalk, i need to connect it to aws rds
heres my database.yml
production:
adapter: postgresql
database: <%= ENV['RDS_DB_NAME'] %> #
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
i am able to connect to my aws db from pgadmin but ones i deploy that database.yml
i get this error
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb db:migrate' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler20200525-23041-9y70lv23041' as your home directory temporarily.
+ '[' false = true ']'
+ su -s /bin/bash -c 'leader_only bundle exec rake db:migrate' webapp
`/home/webapp` is not a directory.
Bundler will use `/tmp/bundler20200525-23045-1bhxksf23045' as your home directory temporarily.
rake aborted!
PG::ConnectionBad: could not connect to server: Connection timed out
Is the server running on host "aapujs6mg3rasw.cxytyfiwlama.us-east-1.rds.amazonaws.com" (172.31.39.107) and accepting
TCP/IP connections on port 3306?
/opt/rubies/ruby-2.6.6/bin/bundle:23:in `load'
/opt/rubies/ruby-2.6.6/bin/bundle:23:in `<main>'
Tasks: TOP => db:migrate
I'm on Cloud9 Ubuntu Template and I installed postgres. I'm getting an error when I try to do a "rake db:migrate".
rake aborted:PG::ConnectionBad: fe_sendauth: no password supplied
Related settings in my database.yml file
default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: <%= ENV['USERNAME'] %>
password: <%= ENV['PASSWORD'] %>
host: <%= ENV['IP'] %>
development:
<<: *default
database: app_development
It seems like Cloud9 issue. I refer https://community.c9.io/t/fe-sendauth-no-password-supplied-error-after-setting-up-postgrsql-on-rails/2206/2
Run below commands on your c9 terminal.
$ source ~/.profile
$ rake db:create
$ rake db:migrate
It works for me.
I am having issues deploying my Rails API to Elastic Beanstalk. I cannot seem to get rid of the following error: ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: ["development", "test"]
Please help me figure this out. I am attaching details below.
/config/database.yml
default: &defaults
adapter: postgresql
encoding: unicode
min_messages: warning
pool: 5
timeout: 10000
username: postgres
host: localhost
production:
<<: *defaults
adapter: postgresql
encoding: unicode
database: <%= ENV['RDS_DB_NAME'] %>
username: <%= ENV['RDS_USERNAME'] %>
password: <%= ENV['RDS_PASSWORD'] %>
host: <%= ENV['RDS_HOSTNAME'] %>
port: <%= ENV['RDS_PORT'] %>
pool: 5
/config/environments/production.rb
config.assets.compile = false
config.assets.initialize_on_precompile = false
EB Logs
[Instance: i-13bf48db] Command failed on instance. Return code: 1 Output: (TRUNCATED)...ib/rails/application.rb:389:in `block in run_tasks_blocks' /home/rof/cache/bundler/ruby/2.1.0/gems/sprockets-rails-2.3.1/lib/sprockets/rails/task.rb:64:in `block (2 levels) in define' Tasks: TOP => environment (See full trace by running task with --trace). Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/11_asset_compilation.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
and
+++ RUBY_VERSION=2.1.5
+++ export GEM_ROOT=/opt/rubies/ruby-2.1.5/lib/ruby/gems/2.1.0
+++ GEM_ROOT=/opt/rubies/ruby-2.1.5/lib/ruby/gems/2.1.0
++ (( 0 != 0 ))
+ cd /var/app/ondeck
+ su -s /bin/bash -c 'bundle exec /opt/elasticbeanstalk/support/scripts/check-for-rake-task.rb assets:precompile' webapp
+ '[' false == true ']'
+ su -s /bin/bash -c 'bundle exec rake assets:precompile' webapp
rake aborted!
ActiveRecord::AdapterNotSpecified: 'production' database is not configured. Available: ["development", "test"]
/home/rof/cache/bundler/ruby/2.1.0/gems/activerecord-4.1.8/lib/active_record/connection_adapters/connection_specification.rb:257:in `resolve_symbol_connection'
If it is not in .gitignore, please give the credentials in your database.yml for the environment that you want to do.
I'm trying to use Travis Continuous Integration on a Rails project. The documentation says that the test db must be configured as following for SQLite3:
test:
adapter: sqlite3
database: ":memory:"
timeout: 500
But I'd like to keep my default configuration for local tests. Is it possible to keep both my local settings and the Travis requirements?
My solution for this problem is fully based on a blog post with a few differences:
Travis CI specific settings in config/database.travis.yml;
cp config/database.travis.yml config/database.yml in before script section of .travis.yml;
I don't have config/database.yml in source tree.
Here is full listing for both files:
# .travis.yml
language: ruby
rvm:
- 1.9.3
env:
- DB=sqlite
- DB=mysql
- DB=postgresql
script:
- RAILS_ENV=test bundle exec rake db:migrate --trace
- bundle exec rake db:test:prepare
- bundle exec rake
before_script:
- cp config/database.travis.yml config/database.yml
- mysql -e 'create database strano_test'
- psql -c 'create database strano_test' -U postgres
# config/database.travis.yml
sqlite: &sqlite
adapter: sqlite3
database: db/<%= Rails.env %>.sqlite3
mysql: &mysql
adapter: mysql2
username: root
password:
database: strano_<%= Rails.env %>
postgresql: &postgresql
adapter: postgresql
username: postgres
password:
database: strano_<%= Rails.env %>
min_messages: ERROR
defaults: &defaults
pool: 5
timeout: 5000
host: localhost
<<: *<%= ENV['DB'] || "postgresql" %>
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
#mrm's blog post doesn't say anything about answering your question.
I faced the same problem where my postgreql credentials are different on my local machine than travis default. This is the simplest solution I came up with:
# config/database.yml
test:
adapter: postgresql
database: medscraper_test
username: <%= ENV['TRAVIS'] ? 'postgres' : 'MY_TEST_USERNAME' %>
password: <%= ENV['TRAVIS'] ? '' : 'MY_TEST_PASSWORD' %>
Note that Travis CI automatically sets TRAVIS environment variable.
Your solution would be:
# config/database.yml
test:
adapter: sqlite3
database: <%= ENV['TRAVIS'] ? '":memory:"' : 'db/test.sqlite3' %>
timeout: 500
I just wrote a blog post describing how to do this.