I have an EC2 instance (m3.medium) that runs my Rails application and connected to an RDS instance for the MySQL database.
When running 'bundle exec rake db:migrate', the process hangs indefinitely without outputting any error. Any ideas on how to debug this?
Edit the database.yml as:-
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: database_name
pool: 5
username: username
password: password
host: abcdef.amazonaws.com
Run the migration as:-
bundle exec rake RAILS_ENV=production db:migrate
Related
This is my database.yml
production:
adapter: mysql2
encoding: utf8
database: testing
pool: 5
username: ubuntu
host: 127.0.0.1
When I run rake db:setup I got this:
Couldn't create database for {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"testing", "pool"=>5, "username"=>"ubuntu", "host"=>"127.0.0.1"}
-- create_table("documents", {:force=>:cascade})
rake aborted!
Mysql2::Error: Access denied for user ''#'localhost' to database 'testing'
Why it's not using my username and host? instead is showing '' # 'localhost'
I think, database.yml config for production environment, but you run it on development environment. You can use 'RAILS_ENV=development rake db:setup' or 'RAILS_ENV=test rake db:setup'
One more thing, database should be created by mysql user with root privileges
So I seemingly successfully installed postgres for production for heroku deployment, but locally rails seems to not find/nor create the database.
When I go to localhost:3000 I get the error:
ActiveRecord::NoDatabaseError
FATAL: database "dimension_development" does not exist Run `$ bin/rake db:create db:migrate` to create your database
When I run $bin/rake db:create I get:
~ already exists
Then, run db:migrate and restart the rails server, reload the page, and get same error.
So I tried instead to run $bin/rake db:create:all and got:
~ already exists
dimension_test already exists
dimension_production already exists
Then did db:migrate again but nothing changed.
If they already exist, why isn't rails finding them? I notice that in the config/db folder there is still the old development.sqlite3 file but no postgres file.
Any idea what could be going on to cause this error?
My database.yml is:
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: dimension_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: dimension_production
pool: 5
timeout: 5000
Thanks! This has got me stumped and I haven't been able to find anything on stackoverflow dealing with this pitfall.
In case of postgresql you will not find any file like development.sqlite3. It's in case of sqlite only.
You did not provided database credential in your database.yml file might causing this error. Try pass username and password as well.
development:
adapter: postgresql
database: dimension_development
pool: 5
timeout: 5000
username: xxxx
password: xxxx
I trying to figure out how fix the active record problem so I can push to heroku.
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
ActiveRecord::AdapterNotSpecified: 'postgresql' database is not configured. Available: ["development", "adapter", "encoding",
"database", "host", "pool", "username", "password", "production"]
development:
adapter: postgresql
encoding: unicode
database: sample_app_development
host: localhost
pool: 5
username: sample_app
password:
test:
adapter: postgresql
encoding: unicode
database: sample_app_test
host: localhost
pool: 5
username: sample_app
password:
production:
adapter: postgresql
encoding: unicode
database: sample_app_production
host: localhost
pool: 5
username: sample_app
password:
There is a space before development in the db config. I believe To fix it, simply remove space from the first line and follow the indentation.
I think you need to write this command on terminal to create you database:
rake db:create
Then run rake db:migrate to run your migrations
Remove spaces on 1st line " development:"
Make sure of the database name e.g. "sample_app_development" or just "sample_app"
gem install pg
rake db:create
rake db:migrate
First install postgresql
gem install pg
Then create project using following command:
rails new myapp -d postgresql
I am running rake db:test:clone RAILS_ENV="test" and I get the error: database configuration does not specify adapter.
My database.yml is as follows:
development:
adapter: postgresql
encoding: unicode
host: localhost
database: mydb_development
username: mydbuser
password:
allow_concurrency: true
pool: 5
min_messages: warning
test:
adapter: postgresql
encoding: unicode
host: localhost
database: mydb_test
username: mydbuser
password:
pool: 5
ps. rake db:test:prepare RAILS_ENV="test" returns the same error.
On "test" I am not sure if host is required. I deleted it and tried again just in case. Any ideas?
Update
When I execute rake db:create:all I get a notice:
mydb_development already exists
Isn't it suppose to also return mydb_test already exists?
I run bundle exec rake db:create RAILS_ENV=test and got the same error.
try to set environment variable before the actual command
RAILS_ENV="test" rake db:test:clone
As per our IRC conversation!
rake db:drop
rake db:create
RAILS_ENV=test rake db:create
RAILS_ENV=test rake db:migrate
I recently switched my test database to be postgrsql from sqlite3. Since doing so, when I follow the instruction here: https://devcenter.heroku.com/articles/rails-asset-pipeline on deploying my assets to heroku, I get the following error:
database configuration does not specify adapter
This happens after running this step
RAILS_ENV=production bundle exec rake assets:precompile
I tried following the instructions from this post and it did not work.
bundle exec rake assets:precompile - database configuration does not specify adapter
I'm guessing it has something to do with my database.yml file, which is here
development:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: localhost
Any ideas?
I figured it out. I added a production section to my database.yml file.
production:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: my_app_url
I didn't think this was needed.
Just pass a dummy database as mentioned in this article:
https://iprog.com/posting/2013/07/errors-when-precompiling-assets-in-rails-4-0
The command is: bundle exec rake RAILS_ENV=production DATABASE_URL=postgresql://user:pass#127.0.0.1/dbname assets:precompile
The problem is you are running
RAILS_ENV=production bundle exec rake assets:precompile
where as your file has development adapter , and so the error comes to be like the adapter is missing.
You need to either change the environment article to development
RAILS_ENV=development bundle exec rake assets:precompile
or change the development directive to production
production:
adapter: postgresql
database: playerpong_database
pool: 5
timeout: 5000
encoding: unicode
host: localhost