我想将 structure.sql 文件中的架构加载到我的Heroku数据库。在我的localhost机器上,我执行如下操作,一切正常,所有表都已创建:
C:\> psql -U postgres -a -d MyApp_development -f C:\MyApp\db\structure.sql
我将本地文件名称作为-f
选项传递:-f C:\MyApp\db\structure.sql
当我在Heroku上做同样的事情时,它会抱怨找不到应用程序。我认为它不理解-f
选项。它无法在其服务器上找到文件C:\MyApp\db\structure.sql
。
那么我如何提供相对于Heroku的正确路径? structure.sql 必须位于Heroku上:
MyApp\db\structure.sql
所以我需要做这样的事情:
heroku pg:psql -U ... -a -d MyHerokuDB -f MyHerokuAppRoot\db\structure.sql
什么是MyHerokuAppRoot
?有什么可以代替吗?
答案 0 :(得分:1)
我找到了解决方案。我认为问题是Postgresql只采用正斜杠(/)作为目录分隔符。因此,当我提供Windows样式路径时,它不起作用。
我做了如下。我先连接到DB:
C:\MyApp>heroku pg:psql DATABASE
然后我运行了这个命令:
d17q2hrd89o9cu=> \i C:/MyApp/db/structure.sql
本地 structure.sql 文件中提到的所有表都是在Heroku主机上创建的。