简体   繁体   English

Ruby on Rails / Postgres-如何为不存在的用户创建新数据库?

[英]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 postgressudo -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.confhost项,而不是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.

相关问题 每当我创建一个新的rails应用程序时,如何创建Postgres用户和数据库? - How can I create a Postgres user and database whenever I create a new rails app? 在Rails中,当父元素尚不存在时,如何创建到新子元素的链接? - In Rails, how do I create a link to a new child element when the parent element doesn't exist yet? Ruby on Rails - 有时该列存在,有时不存在。 我转储数据库时是否与此 Postgres 错误有关 - Ruby on Rails - Sometimes the column exists, sometimes it doesn't. Is it related to this Postgres error when I dump the Database Ruby on Rails:我无法创建新用户 - Ruby on Rails: I cannot create a new user Ruby on Rails检测到用户,但仍返回不存在的错误 - Ruby on Rails detecting a user, but still returning an error that it doesn't exist 无法在Ruby on Rails中创建数据库 - Can't create a database in Ruby on Rails Rails应用程序Postgres角色不存在 - Rails app Postgres role doesn't exist 如何为新的Rails项目创建新的postgres用户? - How to create new postgres user for a new Rails project? Ruby on Rails:用户未从 postgres 数据库中删除 - Ruby on Rails: User not deleting from the postgres database Rails 4:无法通过登录为用户创建会话,尽管该会话是在创建新用户时创建的 - Rails 4: Can't create a session for a user through login, although the session is created when I create a new user
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM