[英]Ruby on Rails/Postgres - How can I create a new database for a user that doesn't exist?
I've cloned a repository, and set up everything via a virtual machine loaded with Ubuntu and using RVM. 我已经克隆了一个存储库,并通过一个装有Ubuntu的虚拟机并使用RVM设置了所有内容。 Everything regarding Ruby on Rails was installed via RVM.
有关Ruby on Rails的所有内容都是通过RVM安装的。
My issue is that, my Ubuntu login is different to the user that I assume the data base wants. 我的问题是,我的Ubuntu登录名不同于我假设数据库想要的用户。 Example, my Ubuntu login is Matt, but when I start rails server and load into the localhost:3000, it is saying this:
例如,我的Ubuntu登录名是Matt,但是当我启动Rails服务器并加载到localhost:3000时,它是这样说的:
ActiveRecord::NoDatabaseError
FATAL: role "James" does not exist
I understand this is a postgres error, but what should I do now to make this work? 我知道这是一个postgres错误,但是现在我应该怎么做才能完成这项工作? I've search through the previous StackOverflow answers and the methods just don't work.
我已经搜索了之前的StackOverflow答案,但是这些方法不起作用。
Eg. 例如。 I've changed
我变了
local all postgres peer
to 至
local all postgres trust
Or using psql -h localhost -U postgres
or sudo -u postgres createuser -s $(whoami); createdb $(whoami)
或者使用
psql -h localhost -U postgres
或sudo -u postgres createuser -s $(whoami); createdb $(whoami)
sudo -u postgres createuser -s $(whoami); createdb $(whoami)
and again, it doesn't work. sudo -u postgres createuser -s $(whoami); createdb $(whoami)
再一次,它不起作用。 The first command asks for a password, which I can't figure out. 第一个命令要求输入密码,我不知道该密码。
You can change the user Rails uses to connect to PostgreSQL by editing <project_root>/config/database.yml
( source ). 您可以通过编辑
<project_root>/config/database.yml
( 源 )来更改Rails用于连接PostgreSQL的用户。
Also, the reason your first psql
command didn't work is -h localhost
requires a host
entry in pg_hba.conf
, not local
. 另外,您的第一个
psql
命令不起作用的原因是-h localhost
需要pg_hba.conf
的host
项,而不是local
。 You can omit the -h localhost
for the local
entry to take effect since the default is to connect via a local socket. 您可以省略
-h localhost
来使local
条目生效,因为默认设置是通过本地套接字连接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.