Question

Can't connect droplet with cluster database | Rails|

Hi guys im new in Digital Ocean and im trying to deploy a personal project. My issue happens when i try to migrate into a production database in a droplet rails app

This is my database.YML

  • default: &default

  • adapter: postgresql

  • encoding: unicode

  • pool: <%= ENV.fetch(“RAILS_MAX_THREADS”) { 5 } %>

  • production:

  • <<: *default

  • secret_key_base: <%= ENV[“SECRET_KEY”] %>

  • username: <%= ENV[“DATABASE_USER”] %>

  • password: <%= ENV[“DATABASE_PASSWORD”] %>

  • database: <%= ENV[“DATABASE”] %>

  • host: <%= ENV[“DATABASE_HOST”] %>

these are the steps im following

  1. Cd Into rails app on VM
  2. rails s -d -b 0.0.0.0 RAILS_ENV=production

At this point the production server is “online”

then i want to get migrations by running this:

  1. rake db:migrate RAILS_ENV=production

and this is the issue:

Caused by:PG::ConnectionBad: FATAL: database “root” does not exist

Rails -v 6.0.3.4

Ruby -v 2.7.1


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
July 1, 2022
Accepted Answer

Hi there,

The error that you are getting indicates that you’ve defined root as the database that you want to use, but that database does not seem to exist.

What I could suggest is:

  • Connect to your Managed database with any SQL client like Table Plus or DBever.
  • Create a new database for your project.
  • Then use that new database in your env variables.

For more information on how to do that you can follow the steps here:

https://docs.digitalocean.com/products/databases/postgresql/how-to/manage-users-and-databases/

Best,

Bobby

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.