Thibault
Thibault

Reputation: 598

Heroku cannot replace DATABASE_URL in configuration (db=${DATABASE_URL})

I have an heroku play 1.2.7 application that worked well in combination with the provided postgres database, the first time I deployed it. I did not change the value of the url of database, but, since, I pushed other commits, and during deployment, heroku tells me :

WARNING: Cannot replace DATABASE_URL in configuration (db=${DATABASE_URL})

However, the command heroku config says :

=== task-reminder Config Vars DATABASE_URL: postgres://zbvzcfzez...amazonaws.com:5432/d4cqrc8kc4tisk HEROKU_POSTGRESQL_GREEN_URL: postgres://zbvzcfzez...amazonaws.com:5432/d4cqrc8kc4tisk

And When I try to acces my app in production, if I do something that access the database, then I have an error...

On top of that, I would take any advice on how to deploy my app, without pushing to git.

Upvotes: 0

Views: 1159

Answers (1)

Regis
Regis

Reputation: 452

Your error is due to the fact that your tables have not been created in production. If you look at the heroku logs, you will see something like this :

ERROR : relation xxxxx does not exist

In production mode, Play does NOT automatically create tables for you. Instead it uses your database evolutions files (in the db/evolutions folder).

So they are two solutions to this :

First you can enable automatic schema update in production mode in your application.conf file.

%prod.jpa.ddl = update
%prod.evolutions.enabled = false

This will update your DB schema when your models change. But it's dangerous though and it's not recommended as it can lead to data loss.

The second solution is to use evolutions. In your application.conf file

%prod.jpa.ddl = none
%prod.evolutions.enabled = true

Then create a file called 1.sql in your db/evolutions folder. This file should take care of creating all your tables :

# --- !Ups
CREATE TABLE mymodel (
    id bigint NOT NULL,
    created timestamp without time zone,
    updated timestamp without time zone,
    email character varying(255),
    name character varying(255)
);

ALTER TABLE ONLY mymodel
    ADD CONSTRAINT mymodel PRIMARY KEY (id);

Create other tables here
....

# --- !Downs

DROP table mymodel;
....

After you have pushed your code to Heroku, you have to first run the db evolutions :

heroku run play evolutions:apply

And then you restart your Heroku server

heroku restart

And then you should be fine. You can read more about Play 1.x evolutions here http://www.playframework.com/documentation/1.2.7/evolutions

Upvotes: 1

Related Questions