致命:角色" root"不存在

时间:2015-01-16 13:19:36

标签: ruby-on-rails postgresql heroku

我已经开始学习使用heroku而我正在尝试执行  bundle exec rake db:create db:migrate命令,我遇到了以下错误,

FATAL:  role "root" does not exist
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:87:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:88:in `create'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:102:in `block in create_current'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:225:in `block in each_current_configuration'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each_current_configuration'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:101:in `create_current'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/var/lib/gems/1.9.1/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"root"}
FATAL:  role "root" does not exist
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:87:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/postgresql_database_tasks.rb:8:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/postgresql_database_tasks.rb:17:in `create'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:88:in `create'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:102:in `block in create_current'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:225:in `block in each_current_configuration'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:224:in `each_current_configuration'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/tasks/database_tasks.rb:101:in `create_current'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:17:in `block (2 levels) in <top (required)>'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:240:in `call'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:240:in `block in execute'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:235:in `each'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:235:in `execute'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:179:in `block in invoke_with_call_chain'
/usr/lib/ruby/1.9.1/monitor.rb:211:in `mon_synchronize'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:172:in `invoke_with_call_chain'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/task.rb:165:in `invoke'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:156:in `invoke_task'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `block (2 levels) in top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `each'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:112:in `block in top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:121:in `run_with_threads'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:106:in `top_level'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:84:in `block in run'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:182:in `standard_exception_handling'
/var/lib/gems/1.9.1/gems/rake-10.4.0/lib/rake/application.rb:79:in `run'
/var/lib/gems/1.9.1/gems/rake-10.4.0/bin/rake:33:in `<top (required)>'
/usr/local/bin/rake:23:in `load'
/usr/local/bin/rake:23:in `<main>'
Couldn't create database for {"adapter"=>"postgresql", "encoding"=>"unicode", "pool"=>5, "database"=>"ruby-getting-started_test"}
rake aborted!
ActiveRecord::NoDatabaseError: FATAL:  role "root" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/connection_handling.rb:87:in `connection'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/migration.rb:909:in `initialize'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in `new'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/migration.rb:807:in `up'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/migration.rb:785:in `migrate'
/var/lib/gems/1.9.1/gems/activerecord-4.1.8/lib/active_record/railties/databases.rake:34:in `block (2 levels) in <top (required)>'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)

我曾尝试编辑schema.rb文件,但没有用。我在Ubuntu上开发这个,请说明我哪里出错了

3 个答案:

答案 0 :(得分:2)

问题是您在名为root的本地计算机上没有ROLE。 在终端中运行:

psql

然后,如果您在终端中连接PostgreSQL:

CREATE ROLE root WITH PASSWORD 'root' WITH CREATEDB LOGIN CREATEROLE CREATEUSER SUPERUSER;

或者只是将database.yml文件用户更改为存在有效密码的用户。

P.S。

不要在您的终端中运行:

heroku run rake db:create

当您第一次将应用程序推送到Heroku的服务器时,Heroku会为您创建数据库。

但你可以跑:

heroku run rake db:migrate

答案 1 :(得分:0)

当你添加Heroku Postgres附加组件(或者只是将一个rails应用程序推送到Heroku,并为你添加一个dev)时,就会为你创建一个数据库。

在Heroku Postgres上不要有趣db:create,它已经创建了。您可以跳到db:migrate等。人

答案 2 :(得分:0)

如果您正在学习rails教程并且想要运行本地服务器,那么您应该拥有gem&#39; sqlite3&#39;在gemfile中,但如果你想将它推送到heroku,你必须更换gem&#39; sqlite3&#39;使用gem&#39; pg&#39;。或者在运行本地服务器时,您可以同时使用它们,但是当您推送到heroku时会因为它没有被支持而感到厌恶。