createuser -P
$ c
(-P是添加密码)
它会问你对于名称,密码,它们是否是超级用户,可以创建新的角色,并且可以创建新的数据库。您可能不需要任何这些rails的权限。
然后创建数据库,以您创建的以下角色运行: createdb -O ROLE_NAME_FROM_PREVIOUS_STEP NEW_DATABASE_NAME
以及中提琴,你应该很好去。
I'm trying to get started with Postgres on Rails apps on Mac. I made a new rails app called "shawsome" and in the database.yml file it created this
development:
adapter: postgresql
encoding: unicode
database: shawsome_development
pool: 5
username: shawsome
password:
But the server wouldn't run because there's no role for "shawsome." Rails just seemed to have inferred the username from the name of my app.
I looked at postgres documentation and it talks about CREATE USER command
CREATE USER jonathan;
However, when I tried to do CREATE USER, it said CREATE comment not found.
Can anyone tell me what I'm doing wrong?
Also, once it's in production (on Heroku) I'm assuming it will also need a username. Will that username remain the same? i.e. if it's configured on my machine, do I need to do anything extra on Heroku?
解决方案
To expand a bit on TheDelChop's answerAfter installation you can run the following in the terminal:
createuser -P
(The -P is to add a password)
It will ask you for name, password, whether they are a superuser, can create new roles, and can create new db's. You probably won't need any of those permissions for rails.
Then create the database to run with the following role you created:
createdb -O ROLE_NAME_FROM_PREVIOUS_STEP NEW_DATABASE_NAME
And viola, you should be good to go.
这篇关于Postgres:创建一个用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!