ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations

ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR: permission denied for relation schema_migrations

我有一个本地项目,有 rails 和 postgres。我把它放在我的 AWS Amazon Linux AMI 上。我在服务器上有 运行 个带有 rails 和 postgres 的测试项目。但是,当我上传本地项目并尝试 运行

rake db:migrate

我收到以下错误:

ActiveRecord::StatementInvalid: PG::InsufficientPrivilege: ERROR:  permission denied for relation schema_migrations

我看到了一些类似的问题,但 none 其中有帮助。我确实有正确的角色设置和连接。

我不确定您 运行宁 rake db:migrateRAILS_ENV 作为生产或开发。无论是哪个(默认为开发),在您的 config/database.yml 中,它都会显示用户、密码和数据库 运行ning。该用户必须对 public.schema_migrations table 具有 ALL 权限。如果是这样,但仍然无法正常工作,请确保该用户拥有 public 架构的所有权限。

阅读更多关于操作 postgres 数据库权限的信息here。 Postgres 有优秀的文档。

还有一件事:如果您在本地创建此数据库,并尝试创建初始数据库而不是实际 运行迁移,请使用 rake db:schema:load 而不是 rake db:migrate. 从不 运行 这在生产中,因为它会删除您的数据!