Database Connections

Deploy failed for a Rails app with this error:

Nov 19 01:33:20 PM Caused by:
Nov 19 01:33:20 PM ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation “schedules” does not exist (ActiveRecord::StatementInvalid)

I connected my database to my service using the internal database URL in the environment variables, which matches my render.yaml with DATABSE_URL. Is there somewhere else I need to check the connection? Both the service and the database are in the same region, Ohio (US East).

Hi there,

Have you run any migrations on your database to create your tables?

Regards,

Keith
Render Support, UTC+10 :australia:

In my render-build.sh I have this:

bundle exec rake db:create
bundle exec rake db:schema:load DISABLE_DATABASE_ENVIRONMENT_CHECK=1

I was able to build and deploy the service with no errors. But there’s no data displayed and I thought the database was connected properly.

EDIT: I got it figured out!

Hi there,

It looks like you updated your build script just to have bundle exec rake db:migrate. Did this help? This is what I would recommend to have in your build script. You for sure don’t need bundle exec rake db:create as your database already exists. bundle exec rake db:schema:load you don’t want to be running every build.

Regards,

Keith
Render Support, UTC+10 :australia:

1 Like

Just curious how you fixed the issue? cc @Keith
I’m also getting the same issue. I checked locally and it works locally when I run bundle exec db:create then db:migrate command and I can see the table from my local db

But when I use the example render-build.sh script, I get
PG::UndefinedTable: ERROR: relation "payola_subscriptions" does not exist

This is the render-build.sh script I used

#!/usr/bin/env bash
# exit on error
set -o errexit

bundle install
bundle exec rake assets:precompile
bundle exec rake assets:clean
bundle exec rake db:migrate

Hi Johnny,

I suspect your migrations don’t include every migration required to create your database schema, so the migration you are running is trying to migrate something that doesn’t exist.

For your very first build, you may need to add bundle exec rake db:schema:load before bundle exec rake db:migrate. Once your build is successful you will need to remove this line and just have bundle exec rake db:migrate.

Regards,

Keith
Render Support, UTC+10 :australia:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.