gpt4 book ai didi

ruby-on-rails - 使用 Ruby on Rails 的 PostgreSQL 用户

转载 作者:行者123 更新时间:2023-11-29 13:01:54 26 4
gpt4 key购买 nike

我正在尝试在 heroku 上部署我的应用程序。为此,我从 sqlite3 更改为 pg,因为 heroku 不支持 sqlite3。我更改了 database.yml 中的内容:

# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: postgresql
pool: 5
timeout: 5000

development:
<<: *default
database: db/development.pg

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.pg

production:
<<: *default
database: db/my_database_production.pg

我也添加并安装了 gem (gem install pg)。当我尝试运行 bundler exec rake db:create 时,出现以下错误:

rake aborted!
ActiveRecord::NoDatabaseError: FATAL: role "flo" does not exist
Run `$ bin/rake db:create db:migrate` to create your database
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:898:in `rescue in connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:888:in `connect'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:568:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/postgresql_adapter.rb:41:in `postgresql_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:435:in `new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:445:in `checkout_new_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:416:in `acquire_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:350:in `checkout'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:265:in `block in connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:264:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:541:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:113:in `retrieve_connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/connection_handling.rb:87:in `connection'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:909:in `initialize'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `new'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:807:in `up'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/lib/active_record/migration.rb:785:in `migrate'
/home/flo/Ruby/sample_app/vendor/bundle/ruby/1.9.1/gems/activerecord-4.1.6/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)

我正在尝试在我的终端中编写 su - postgres 但从该命令我得到:

No passwd entry for user 'postgres'

我该怎么办?

最佳答案

您需要将用户“flo”添加到您的本地 postgres 实例(我通常只是将他们添加为 super 用户,所以我没有权限问题)。在您的终端中运行:

createuser -P -s -e flo

系统还会提示您设置密码。现在让我们使用“flo”。然后,您需要将其添加到您的 databases.yml 文件中:

development:
<<: *default
database: db/development.pg
username: flo
password: flo

执行此操作,然后再次尝试运行 rake db:create。检查this out for additional help .

关于ruby-on-rails - 使用 Ruby on Rails 的 PostgreSQL 用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276932/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com