setting up a postgresql database - ruby-on-rails

I am getting the error below when I try creating a database. Here is the database.yml:
default: &default
adapter: postgresql
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
adapter: postgresql
encoding: unicode
database: MyDatabase
host: localhost
pool: 5
username: name
password: name`
# 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. postgresql
production:
adapter: postgresql
encoding: unicode
database: MyDatabase_Production
host: localhost
pool: 5
username: name
password: name
role: MyRole
Here is the error:
Database 'MyDatabase' already exists
PG::SyntaxError: ERROR: syntax error at or near "."
LINE 1: CREATE DATABASE "db/test"." postgresql" ENCODING = 'utf8'
^
Couldn't create 'db/test. postgresql' database. Please check your configuration.
rails aborted!
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "."
LINE 1: CREATE DATABASE "db/test"." postgresql" ENCODING = 'utf8'
^
Caused by:
PG::SyntaxError: ERROR: syntax error at or near "."
LINE 1: CREATE DATABASE "db/test"." postgresql" ENCODING = 'utf8'
^
Tasks: TOP => db:create
(See full trace by running task with --trace)
I am getting the error above when I run rails db:create up my posgresql database

It looks like maybe some of your text config got deleted. Should be something like:
test:
<<: *default
database: test
username: name
password: name

There is a syntax error in database configuration as stated in the error
<<: *default
database: db/test. postgresql
There is a dot and blank space that are not allowed. Renaming it to something else will solve the problem.
Example:
<<: *default
database: db/test_postgresql

Related

Unable to create Database in Rails using rake db:create

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'

database "db/development.sqlite3" does not exist - how to fix?

a friend deployed my application on Heroku, and it works fine there. But I can not open my application on local server. Can anyone help?
When going on localhost i get the following error message:
ActiveRecord::NoDatabaseError
FATAL: database "db/development.sqlite3" does not exist
Extracted source (around line #661):
rescue ::PG::Error => error
if error.message.include?("does not exist")
raise ActiveRecord::NoDatabaseError.new(error.message, error)
else
raise
end
Update your database.yml
default: &default
adapter: postgresql
encoding: utf8
development:
<<: *default
database: your_app_development
username: your_usernmae
password: your_password
I solved this by changing database.yml file to actually be the names of the database you want to create like database: my_app_development
ex:
development:
<<: *default
database: ***_development
You need to change database: and run rails db:create
then rails db:migrate RAILS_ENV=development

Rake db:create fails to connect to server: No such file or directory

I'm trying to upload a rails app to heroku and I'm running into problems to change my app from sqlite3 to postgres, mainly when I run rake db:create I get:
could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
This is what my database.yml looks like:
default: &default
adapter: postgresql
pool: 5
timeout: 5000
development:
<<: *default
database: anagram_development
# 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: anagram_test
production:
<<: *default
database: anagram_production
Do you have postgresql installed locally? If so, double check that it's running. Your database.yml file is also missing some required information to connect to a postgres database. You need to provide username, password and hostname.
Here's an example of mine which connects to a local postgres db:
development:
adapter: postgresql
encoding: unicode
database: app_development
pool: 10
username: <%= %x(whoami) %>
password:
For heroku/production, you can use the following:
production:
url: <%= ENV['DATABASE_URL'] %>
pool: <%= ENV['DB_POOL'] || 10 %>

Can't rake db:migrate

When I'm trying to migrate my database I get an error Mysql2::Error: Table 'database.lorem_ipsum' doesn't exist: SHOW FULL FIELDS FROM ``lorem_ipsum. I've created database before by rake db:migrate
config/database.yml
development:
adapter: mysql2
database: database
username: root
password:
Can you try this ?
test:
adapter: mysql2
encoding: utf8
reconnect: false
database: database
pool: 5
username: root
password:
On your database.yml

rake aborted error while implementing db:drop in rails 3.2

I am new to rails.I was trying rake db:drop but am getting the following error
rake aborted!
(<unknown>): mapping values are not allowed in this context at line 21 column 12
/home/chiron/.rvm/gems/ruby-1.9.3-p327/gems/railties-3.2.11/lib/rails/application/configuration.rb:115:in `database_configuration'
/home/chiron/.rvm/gems/ruby-1.9.3-p327/gems/activerecord-3.2.11/lib/active_record/railties/databases.rake:25:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:drop => db:load_config
(See full trace by running task with --trace)
I am installing on ubuntu.While working the same code for windows environment it seems to work perfectly
My database.yml is as follows:-
# PostgreSQL v0.8.x
# gem install pg
development:
adapter: postgresql
encoding: unicode
host: localhost
database: lib_development
pool: 5
username: chiron
password:
# 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:
adapter: postgresql
encoding: unicode
host: localhost
database: lib_test
pool: 5
username: chiron
password:
production:
adapter: postgresql
encoding: unicode
host: localhost
database: lib_production
pool: 5
username: chiron
password:
Can anyone please help me
you have redundant spacebar in config
pool: 5
username: chiron # << here
password:

Resources