从位于(heroku.com)的应用程序连接到位于(pythonanywhere.com)的MySQL数据库, [英] Connecting to MySQL database located at (pythonanywhere.com) from app located at (heroku.com)
问题描述
我创建了一个webb应用程序并将其部署到Heroku。到现在为止还挺好。现在我需要将它与位于pythonanywhere.com上的MySQL数据库集成。
我尝试了以下命令(这是我在搜索访问时设法找到的来自Heroku的远程MySQL数据库):
lockquote
heroku config:add DATABASE_URL = mysql2:// PYTHONANYWHERE_USER:DATABASE-HOST-ADDRESS / DATABASE- NAME - app HEROKU-APP-NAME
每当我在Heroku的控制台中运行这个命令时,我会收到以下消息:
bash:heroku:找不到命令
有没有人试过从Heroku连接到pythonanywhere MySQL数据库?你可以证明你是如何做到这一步的吗?
我之所以想要访问PythonAnywhere数据库(而不是将它托管在Heroku上)是因为很多后端是在PythonAnywhere上编写的,并存储在该数据库中。
谢谢,
heroku
命令由 Heroku CLI ,并且应该从本地计算机安装并运行 。直接从dyno(例如,通过 heroku run bash
)运行 heroku
命令将不起作用。
使用 heroku config
设置 DATABASE_URL
之后,您应该可以通过 process.env.DATABASE_URL
来从您的代码访问它。
I created a webb app and deployed it at Heroku. So far, so good. Now I need to integrate it with the MySQL database which is located at pythonanywhere.com.
I tried the following command (which is what I managed to find when googling for accessing a remote MySQL database from Heroku):
heroku config:add DATABASE_URL=mysql2://PYTHONANYWHERE_USER:DATABASE-HOST-ADDRESS/DATABASE-NAME--app HEROKU-APP-NAME
Whenever I run this command from the console in Heroku, I get the following message:
bash: heroku: command not found
Have anyone tried connecting to a pythonanywhere MySQL database from Heroku before? Can you show how you did this step-by-step?
The reason why I want to access the PythonAnywhere database (and not just host it on Heroku) is that a lot of the backend is written on PythonAnywhere and stored on that database.
Thanks,
The heroku
command is provided by the Heroku CLI, and should be installed and run from your local machine. Running heroku
commands directly from a dyno (e.g., via heroku run bash
) won't work.
Once you've set DATABASE_URL
using heroku config
you should be able to access it from your code via process.env.DATABASE_URL
.
这篇关于从位于(heroku.com)的应用程序连接到位于(pythonanywhere.com)的MySQL数据库,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!