Home > Software engineering >  Rails error when firing up a cloned API - ActiveRecord::ConnectionNotEstablished
Rails error when firing up a cloned API - ActiveRecord::ConnectionNotEstablished

Time:11-01

As the title says, I clones a rails API. I tried to follow the steps in this article from point 2 onwards enter image description here

Please help!

I have tried googling the answer and phoning a friend.

I have tried rails db:setup, rails db:seed, rails db:create, rails db:migrate.

CodePudding user response:

You want to initialize the postgres db, which doesn't quite come for free. I recommend using sqlite3 until you need a production db. If the clone calls for PG, then:

  1. (user) $ sudo su - postgres
  2. (postgres) $ createuser --interactive
  3. (local) $ sudo systemctl restart postgresql
  4. (local) $ bundle exec rails db:create:all

$ pg_isready tells you at a glance if posgtres server/cluster is online.

$ pg_isready
/tmp:5432 - accepting connections

If it gets frustrating, change the config/database.yml to the default version, remove pg gem if possible, add sqlite3. Then simple rake db:migrate after creating or adding an [environment].sqlite3 file to db/

#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000

development:
  <<: *default
  database: db/development.sqlite3

# 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.sqlite3

production:
  <<: *default
  database: db/production.sqlite3



CodePudding user response:

Update

Thank you for the help. I was able to find out as my partner had created the backend, the issue was arising because the owners of the database didn't match when I cloned his repo.

  • Related