最初,当我在Heroku(免费的)上提供数据库时,我的应用程序获得了一个名为DATABASE_URL
的新环境变量,它指向一个新创建的数据库,我的应用程序使用这个数据库。
今天,当我通过UI在Heroku(付费)上提供新数据库时,我得到了一个名为HEROKU_POSTGRESQL_MAUVE_URL
的新环境变量,它指向新数据库。
如何将Heroku应用指向这个新配置的数据库HEROKU_POSTGRESQL_MAUVE_URL
?
我希望我的数据库URL与HEROKU_POSTGRESQL_MAUVE_URL
交换,但没有发生。
1条答案
按热度按时间31moq8wy1#
This happens when your app has multiple databases:
As part of the provisioning process, a
DATABASE_URL
config var is added to your app’s configuration.DATABASE_URL
contains the URL your app uses to access the database. If your app already has a Heroku Postgres database and you’ve provisioned another one, this config var’s name instead has the formatHEROKU_POSTGRESQL_<COLOR>_URL
(for example,HEROKU_POSTGRESQL_YELLOW_URL
You can promote your new database to make it the primary database:
pg:promote
updates the value of theDATABASE_URL
config var with the newly promoted database’s connection string. It also creates an alternate attachment for the old primary database, assigned with a newHEROKU_POSTGRESQL_<color>_URL
config var. The promotion process triggers a release and restarts the app.For example:
You should continue to use the
DATABASE_URL
environment variable to connect to your database.