Home > Back-end >  setting up a postgresql database
setting up a postgresql database

Time:11-21

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

CodePudding user response:

It looks like maybe some of your text config got deleted. Should be something like:

test:
  <<: *default
  database: test
  username: name
  password: name

CodePudding user response:

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