gpt4 book ai didi

ruby-on-rails - 在现有项目上使用 Rails 设置 postgresql 数据库

转载 作者:太空宇宙 更新时间:2023-11-03 18:14:12 26 4
gpt4 key购买 nike

我是 Rails 和 Ruby 的新手,我正在尝试让现有项目在我的环境中运行,我正在使用 Ubuntu 14.04 和 Rubymine、Rails 4.2 和 Ruby 2.2.0

这是迁移文件:

class CreatePeople < ActiveRecord::Migration
def change

create_table :people do |t|
t.string :pid, limit: 20, null: false
t.string :firstname, limit: 40, null: false
t.string :lastname, limit: 40, null: false
t.integer :age
t.string :gender, limit: 4, null: false
t.datetime :birthday
t.string :country, limit: 2
t.timestamps null: false
end

add_index :people, :firstname
add_index :people, :lastname
add_index :people, :country
add_index :people, :pid, unique: true
end
end

我的数据库.yml:

config=/opt/local/lib/postgresql84/bin/pg_config

default: &default
adapter: postgresql
encoding: unicode
pool: 5

development:
<<: *default
database: vasco_annuaire

<<: *default
database: annuaire_test


<<: *default
database: annuaire_production
username: annuaire
password: <%= ENV['ANNUAIRE_DATABASE_PASSWORD'] %>

运行 rake db:create 给我

"role ferenan does not exist"

启动 localhost:3000 给出

ActiveRecord::NoDatabaseError FATAL: role "ferenan" does not exist

Extracted source (around line #661): 659 660 661 662 663 664

    rescue ::PG::Error => error
if error.message.include?("does not exist")
raise ActiveRecord::NoDatabaseError.new(error.message, error)
else
raise
end

我也无法通过 Pg-Admin-III 连接到 Postgresql

server name : Postgresql
host : localhost
port : 5432
maintenance_db : postgres
username : postgres
no password

使用这些参数我得到消息:

fe_sendauth : no password supplied

我已将此行添加到我的 pg_hba.conf 中:

host    sa    all         192.168.0.nnn/32     trust

还有这个到我的 postgresql.conf:

listen_addresses = '*'

然后运行以下命令:

sudo /etc/init.d/postgresql reload

我不知道该做什么以及如何让这些东西协同工作,但该项目确实像我的上司之前向我展示的那样有效,不幸的是,他目前无法帮助我解决这个问题。非常感谢任何帮助。

最佳答案

默认情况下,当未指定用户名时,postgesql 会尝试使用当前用户(在您的情况下为 ferenan)进行连接,但在 vanilla 安装中,不存在这样的角色。

要连接到角色 postgres,请将您的 database.yml 更改为:

default: &default
adapter: postgresql
encoding: unicode
pool: 5
username: postgres

关于 Pg-Admin-III,您似乎正尝试从 localhost 进行连接,因此我建议您尝试将以下内容添加到 pg_hba.conf (它信任来自具有 md5 授权的本地主机的请求):

host    all             all             127.0.0.1/32            trust

关于ruby-on-rails - 在现有项目上使用 Rails 设置 postgresql 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28880945/

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