2014-04-28 81 views
11

我想使用PostgreSQL,以便我可以部署到Heroku。但是我不能再运行localhost为什么?我得到以下信息:PG :: ConnectionBad致命错误:角色“我的名字”不存在

PG::ConnectionBad 
FATAL: role "Myname" does not exist 

这里是我的databse.yml

development: 
    adapter: postgresql 
    database: my_database_development 
    pool: 5 
    timeout: 5000 

test: 
    adapter: postgresql 
    database: my_database_test 
    pool: 5 
    timeout: 5000 

production: 
    adapter: postgresql 
    database: my_database_production 
    pool: 5 
    timeout: 5000 

这里是我的Gemfile:

source 'https://rubygems.org' 

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.0.3' 

# Use pg as the database for Active Record 
gem 'pg' 

# Use SCSS for stylesheets 
gem 'sass-rails', '~> 4.0.0' 

# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 

# Use CoffeeScript for .js.coffee assets and views 
gem 'coffee-rails', '~> 4.0.0' 

# See https://github.com/sstephenson/execjs#readme for more supported runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 

# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 

# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 1.2' 

group :doc do 
    # bundle exec rake doc:rails generates the API under doc/api. 
    gem 'sdoc', require: false 
end 

# Use ActiveModel has_secure_password 
# gem 'bcrypt-ruby', '~> 3.1.2' 

# Use unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano', group: :development 

# Use debugger 
# gem 'debugger', group: [:development, :test] 

gem 'rails_12factor', group: :production 

看来,皮克需要我创建一个用户或DATABSE但是我无法或不知道如何。找不到任何适用于我的命令(我在Windows btw上)

我该怎么办?

+0

你应该给''database.yml'文件输入'username'和'password' – Pavan

+0

我怎么知道我的密码是什么? – user3408293

回答

0

我不得不进入我的PG管理仪表板和建立DB /用户那里。不幸的是,它位于与在线教程不同的子目录中(可能更新了目录目的地的最新更新)。幸运的是,我能够找到它并在那里创建表/用户,更新我的database.yml文件,然后我的应用程序就能够工作了!

0

您应该创建一个usernamepasswordPostgresql

尝试在psql

CREATE USER Myname WITH PASSWORD 'your_password'; 

创建带有密码的用户而你应该添加那些你database.yml作为

username: Myname 
password: your_password 
+0

这不起作用。创建命令未找到 – user3408293

+0

@ user3408293运行命令的位置?尝试运行'psql'。 – Pavan

+0

我的应用程序目录中的命令行 – user3408293

0

@ user3408293

  1. 安装后创建PostgreSQL的用户

    须藤Postgres的-u CREATEUSER --superuser $ USER

    须藤Postgres的-u CREATEUSER pgs_root

  2. 设置用户密码为PostgreSQL用户

    sudo -u postgres psql postgres

    (对于psql提示符)的Postgres =#\密码时应为ex.-的Postgres =#\密码时应pgs_root

N.B你也应该不同环境中的database.yml文件中添加用户名和密码。

您也可以参考以下链接:Rails: Error installing pg gem

+0

sudo命令在我的电脑上不起作用。相信它不适用于Windows – user3408293

+0

这可能会帮助你。 http://superuser.com/questions/42537/is-there-any-sudo-command-for-windows – Addicted

+0

实际上,我在Windows机器上使用gitbash而不是Windows命令行抱歉应该指定。太差劲了几乎我不能做任何事情.. – user3408293

0

在Windows上,我相信这是一个更容易一些。

为您的系统安装postgresql和PGAdmin。请参阅this

创建一个名为postgres的用户并为其提供密码。你会很好地提示做到这一点。

然后,当您想要create databases时,只需右键单击您的连接并选择新建数据库。这些数据库的名称应与您所写的内容相对应database.yml

运行rake db:migrate RAILS_ENV=development(开发测试)。

这些步骤为我工作。

18

的错误是 “角色 ”的Myname“ 不存在”,

创建用户 “的Myname” 对PostgreSQL

须藤Postgres的-u CREATEUSER --superuser的Myname

它会解决这个问题。

4

对我而言有效的是:createuser -P -d -e Myname

-P If given, createuser will issue a prompt for the password of the new user. 
     This is not necessary if you do not plan on using password authentication. 
-d The new user will be allowed to create databases. 
-e Echo the commands that createuser generates and sends to the server. 

如果您对OSX自制安装PostgreSQL,没有默认postgres用户,你将不能够直接使用psql没有首先建立一个用户。

+0

我已经做到这一点之前,我不知道为什么需要再次做到这一点... – rld

相关问题