Rails Deploy Errors

I am deploying my first Rails app. I converted the db to PostgreSQL from SQLite, and in my development db, I was able to get around this error:

Caused by:
Nov 18 10:30:06 AM PG::DatatypeMismatch: ERROR: column “exp” cannot be cast automatically to type integer (PG::DatatypeMismatch)
Nov 18 10:30:06 AM HINT: You might need to specify “USING exp::integer”.

by running db:schema:load after creating the db. But when I change my build command in bin/render-build.sh I get this:

rake aborted!
Nov 18 10:37:31 AM ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your ‘production’ database. (ActiveRecord::ProtectedEnvironmentError)
Nov 18 10:37:31 AM If you are sure you want to continue, run the same command with the environment variable:
Nov 18 10:37:31 AM DISABLE_DATABASE_ENVIRONMENT_CHECK=1

I’m not sure what I should do to get my Rails app to deploy.

Hi there,

In a production environment, you do not want to be running db:schema:load this will drop your current schema and re-create it. This may be fine locally where your data likely isn’t important, but unless you are just setting up your database for the first time you don’t want to be running this on Render/production. Rails is trying to protect you from deleting your production data by having you set DISABLE_DATABASE_ENVIRONMENT_CHECK=1, this is a “are you really sure” check.

This will have fixed your migration issue locally because running db:schema:load will have deleted your data causing the migration error. You will have been migrating an empty database.

On Render to fix this, you will want to look at the data in the column you are migrating to make sure they are all integers and manually update the ones that aren’t. Then retry running the migration.

Regards,

Keith
Render Support, UTC+10 :australia:

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