为什么我不能在Windows中迁移我的postgres数据库?

时间:2018-02-28 19:45:19

标签: ruby-on-rails windows postgresql

我将数据库从sqlite切换到postgres,以便在heroku上进行部署。当我这样做并试图运行heroku运行rake db:migrate -a我看到了这个错误: ActiveRecord :: StatementInvalid:PG :: DatatypeMismatch:ERROR:column" pay_date"不能自动转换为输入日期提示:您可能需要指定"使用pay_date :: date"。 :ALTER TABLE" recurring_payments" ALTER COLUMN" pay_date" TYPE日期  所以我创建了一个迁移来解决这个问题,但是当我运行rake db:migrate来运行迁移时,我看到了这个错误:

PG::ConnectionBad: could not connect to server: No such file or directory
    Is the server running locally and accepting
    connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?

然而,当我检查我的服务时,我发现它正在运行,并且它被配置为侦听端口5432.还有什么可能导致此问题?

另外,如果我将此行添加到database.yml:

  host: localhost 

错误更改为:

PG::ConnectionBad: could not translate host name "localhost" to address: Name or service not known 

也许这更有希望?

1 个答案:

答案 0 :(得分:0)

您似乎遇到了多个问题:

默认情况下,Rails使用Unix套接字连接到PostgreSQL。因此原始的错误信息。

添加host密钥会将Rails切换到TCP / IP连接,这是您在Windows中所需的。

现在您似乎还有另一个问题:localhost无法解析为IP地址,这表明您的Windows计算机上存在与Rails或PostgreSQL无关的常规配置问题。

检查您的hosts文件是否搞砸了,或者您的(个人)防火墙是否阻止了Rails或PostgreSQL。尝试运行ping localhost

如果其他所有方法都失败,请尝试使用host: 127.0.0.1

相关问题