Rails的数据库:迁移与容器中运行的Postgres

在我的开发环境我有postgres在一个容器中运行,运行db:migrate工作正常,直到最近我需要改变架构为SQL

config.active_record.schema_format = :sql 

不是当我运行db:migrate时出现以下错误:

 pg_dump: [archiver (db)] connection to database "mydatabase" failed: FATAL: password authentication failed for user "myuser" 

在我看来,pg_dump忽略database.yml设置。 其他人有这种设置的运气?

我最终做的是在你使用的Ubuntu中安装postgresql-client-common和postgresql-client。

 sudo apt install postgresql-client-common postgresql-client 

这在本地给了我pg_dump,然后我在docker机器上打开了一个terminal,并把host all all 0.0.0.0/0 trust添加到了默认的pg_hba.conf文件

打开一个shell使用:

 docker exec -i -t <idOfContainer> /bin/bash 

添加行:

 cd /var/lib/postgresql/data echo host all all 0.0.0.0/0 trust >> pg_hba.conf 

最后一步是你需要将你的本地用户添加到postgress中,pg_dump不会使用来自datbaase.yml的凭证,所以你应该连接到psql并运行:

 CREATE USER <youruser>