Home > other >  rails database setup command can not make the database as I wish?
rails database setup command can not make the database as I wish?

Time:02-03

I am newbie with Ruby Rails and here is my problem.

I created a very simple Rails program by this command

rails new freelancer --database=postgresql --javascript=webpack

And I had no error

In this file

config -> locales -> database.yml

I saw 2 files

database: freelancer_test database: freelancer_development

Then I ran this command

rails db:setup

It showed me this error

Is the server running locally and accepting connections on that socket? Couldn't create 'freelancer_development' database. Please check your configuration. rails aborted! ActiveRecord::ConnectionNotEstablished: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? Caused by: PG::ConnectionBad: connection to server on socket "/tmp/.s.PGSQL.5432" failed: No such file or directory Is the server running locally and accepting connections on that socket? Tasks: TOP => db:setup => db:create (See full trace by running task with --trace)

I thought that it must created 2 databases freelancer_test and freelancer_development ?

Could you please give me some advices ? Thank you in advance.

CodePudding user response:

A Postgresql server is required and configured properly to run this Rails application. From the error it expects a postgres server running locally. But you can also connect to a standalone DB server remotely.

Your database.yml should contain correct connection info then run the same command again.

CodePudding user response:

It means that you have no PostgreSQL instance running locally.

Two choices:

Unless you're really need PostgreSQL features for your development, I'd go for the second option, as you're beginner with RoR, you probably want to focus on the development of your app first. Using the default sqlite database requires no dependencies as the database is a text file in the end.

You can create the app with the following command:

rails new freelancer --javascript=webpack
  • Related