heroku pg:不要从heroku数据库获取表格 [英] heroku pg: pull not fetching tables from heroku database

查看:209
本文介绍了heroku pg:不要从heroku数据库获取表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



heroku pg:pull HEROKU_POSTGRESQL_COLOR mydatabase - 使用heroku bash命令将一个heroku数据库拉到我的本地Windows计算机上。 -app appname



当我运行上述命令时,出现以下错误:

< blockquote>

'env'不被识别为内部或外部命令,可操作程序或批处理文件。

但是创建了本地数据库'mydatabase',但没有任何表。



我的heroku应用程序的数据库中有一个表格,但它不会被拉到我的本地数据库。



帮助我解决它。

解决方案



1.当出现错误,例如'env'未被识别为内部或外部命令,可操作程序或批处理文件时,表示系统正在尝试执行名为env的命令。这与设置环境变量无关。



Env不是windows中的命令,而是unix中的命令。我知道你有一台Windows机器。你可以做的是运行git bash。 (你可以自己得到它,但它带有Heroku的CLI)。



这给你一个类似unix的环境,支持env命令,然后你可以运行实际的heroku pg:pull命令。



2.如果仍然不起作用,可以使用一种解决方法,不需要额外安装任何东西。其实这是基于我提交给Heroku的一张票,所以我只想引用他们的回应:



pg:push命令只是一个包装 pg_dump pg_restore 命令由于您遇到的错误,听起来我们应该继续前进并手动执行。这些使用cmd.exe(命令提示符应用程序,您首先报告错误)。首先从您的heroku应用程序配置变量中获取连接字符串。

  heroku config:get DATABASE_URL 

然后,您要挑选用户名/主机名/数据库名部分从连接字符串,即:postgres:// username:password @ hostname:port / databasename。在以下命令中使用这些变量,并在提示输入密码时粘贴密码,这会将您的heroku数据库的内容转储为本地文件。

  pg_dump --verbose -F c -Z 0 -U用户名-h主机名-p端口数据库ename> heroku.dump 

接下来,您会将此文件加载到本地数据库中。在运行此命令之前,CLI执行的一件事是检查并确保目标数据库为空,因为在真实数据的数据库上运行该命令是您想要避免的,因此请小心使用pg_restore。当手动运行时,可能会冒无数CLI检查的风险,因此您可能需要手动验证目标数据库是否为空。

  pg_restore --verbose --no-acl --no-owner -h localhost -p 5432 -d mydb2< heroku.dump 

对不起,这不是一个更好的体验,我希望这会帮助你取得进步。我们正在重写我们的pg命令,以便它们可以在包括windows在内的所有平台上更好地工作,但是当它完成时没有可靠的时间表。


I'm trying to pull a heroku database to my local Windows computer by using heroku bash command

heroku pg:pull HEROKU_POSTGRESQL_COLOR mydatabase --app appname,

when I running above command I get the following error:

'env' is not recognized as an internal or external command, operable program or batch file.!

But local database 'mydatabase' is created, but without any tables.

My heroku app's database has a table in it, but it is not getting pulled to my local database.

Help me to solve it.

解决方案

a couple of things:

1.When there is an error such as "'env' is not recognized as an internal or external command, operable program or batch file" it means that the system is trying to execute a command named env. This has nothing to do at all with setting up your environment variables.

Env is not a command in windows, but in unix. I understand that you have a windows machine though. What you can do is run "git bash". (You could get it by itself but it comes with Heroku's CLI).

This gives you a unix-like environment where the "env" command is supported, and then you can run the actual heroku pg:pull command.

2.If that still doesn't work, there is a workaround which works,without installing anything extra. Actually this is based on a ticket which I submitted to Heroku so I'm just going to quote their response:

"The pg:push command is just a wrapper around pg_dump and pg_restore commands. Due to the bug you encountered, it sounds like we should go ahead and do things manually. Run these using cmd.exe (The Command Prompt application you first reported the bug). First grab the connection string from your heroku application config vars.

heroku config:get DATABASE_URL

Then you want to pick out the username / hostname / databasename parts from the connection string, ie: postgres:// username : password @ hostname : port / databasename. Use those variables in the following command and paste in the password when prompted for one. This will dump the contents of your heroku database for a local file.

pg_dump --verbose -F c -Z 0 -U username -h hostname -p port databasename > heroku.dump

Next you will load this file into your local database. One thing that the CLI does before running this command is to check and make sure the target database is empty, because running this against a database with real data is something you want to avoid so be careful with pg_restore. When running this manually you run the risk of mangling your data without the CLI check, so you may want to manually verify that the target database is empty first.

pg_restore --verbose --no-acl --no-owner  -h localhost -p 5432 -d mydb2 < heroku.dump

I am sorry this is not a better experience, I hope this will help you make progress. We are in the process of rewriting our pg commands so that they work better on all platforms including windows, but there is no solid timeline for when this will be completed."

这篇关于heroku pg:不要从heroku数据库获取表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆