gpt4 book ai didi

sql - 设置 PostgreSQL 和 db :rake 时出现问题

转载 作者:太空宇宙 更新时间:2023-11-04 04:00:28 25 4
gpt4 key购买 nike

我在为我正在从事的项目设置 Postresql 时遇到了很多问题。

<小时/>

一些信息:

-我正在运行 Ubuntu 12.04

-我安装了 postgres 用户帐户

-我正在尝试使用 RoR 中的项目。

<小时/>

我正在尝试使用此命令:

“捆绑执行rake db:创建”

我尝试以 sudo、计算机用户和 postgres 的身份使用它。

当我以计算机用户身份运行它时,它返回“fe_sendauth:未提供密码”,然后中止 rake。

知道我的(用户帐户) ruby​​ 版本是2.1.0,因为当我运行“ruby --version”时,它会返回

“ruby 2.1.0p0(2013-12-25 修订版 44422)[x86_64-linux]”

但是,当我运行“ruby --version”作为postgres时,它会返回

“ruby 2.0.0p353(2013-11-22 修订版 43784)[x86_64-linux]”

如何为我的用户帐户和 postgres 提供单独的 ruby​​ 版本?我尝试使用 sudo 通过 RVM 更改 ruby​​ 版本,但权限被拒绝。

我不记得为 postgres sudo 设置了密码,而且我无法弄清楚。

我能做什么

  1. 恢复/重置我的 sudo postgres 密码。
  2. 完成第 1 步后,在 postgres 帐户上安装/设置最新 (2.1.0) 版本的 ruby​​。
  3. 在这一切之后运行bundle exec rake db:create?

最佳答案

嗯,不确定 Linux 是否有任何具体问题,但听起来您已经安装好了。

如果不查看你的database.yml就很难说,但rails约定似乎是使用用户名<%= your_project_name %>和空白密码连接到数据库。根据错误,您可能没有在 postgres 中创建这样的用户/角色。

# enter the psql shell as the postgres admin user
psql -d postgres
CREATE ROLE <%= your_project_name %> WITH LOGIN CREATEDB SUPERUSER;
\q

# create the dbs and load the schema
bundle exec rake db:create
bundle exec rake db:schema:load
bundle exec rake db:migrate
bundle exec rake db:test:prepare

# revoke superuser, it was just there in case there were any extensions that needed installing
psql -d postgres
ALTER ROLE <%= your_project_name %> WITH NOSUPERUSER;
\q

这应该可以做到这一点,尽管听起来您也可能遇到 RVM 问题。网站上有大量有关 RVM 的文档。

您还可能会将数据库中的用户/角色的概念与操作系统中的用户的概念混淆。您应该能够使用任何 UNIX 用户访问数据库,但您需要使用 database.yml 对数据库进行身份验证。如上所述,我见过的大多数 Rails 项目似乎都使用默认值,但当然您可以使用任何您想要的。

关于sql - 设置 PostgreSQL 和 db :rake 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23177951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com