簡體   English   中英

如何為本地Rails項目設置Postgres數據庫?

[英]How to set up Postgres database for local Rails project?

我最近買了一台新機器,現在想從Github處理我的項目。 我很好奇如何在我的本地機器上正確設置Postgres數據庫。 我在Ubuntu(12.04)上安裝了postgresqlpgadmin3libpq-dev

我拉下項目:

git clone https://github.com/thebenedict/cowsnhills.git

並運行:

bundle

當我跑:

rake db:create && rake db:schema:load

我收到此錯誤:

rake db:create && rake db:schema:load
FATAL:  password authentication failed for user "cnh"
FATAL:  password authentication failed for user "cnh"
....

config/database.yml文件如下所示:

development:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_development
  pool: 5
  username: cnh
  password: cnh

test:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_test
  pool: 5
  username: cnh
  password: cnh

production:
  adapter: postgresql
  encoding: unicode
  host: localhost
  database: cnh_production
  pool: 5
  username: cnh
  password: cnh

設置Postgres數據庫的正確方法是什么,以便我可以在本地計算機上運行此項目?

現在,當我啟動Rails服務器時,我得到:

在此輸入圖像描述

在尋找相同的答案時,我遇到了你的問題。 我試圖按照@ prasad.surase給你的指示。 我發現的問題是ppa存儲庫將在12.04 LTS即將貶值。 相反,我找到了這個鏈接,它真的有幫助。

在Ubuntu 12.04中進行Rails開發的PostgreSQL設置

  1. 通過包管理器安裝postgresql和admin工具

     sudo apt-get install postgresql libpq-dev phppgadmin pgadmin3 
  2. 以postgres用戶身份登錄postgresql提示符

     sudo su postgres -c psql 
  3. 為您的項目創建一個postgresql用戶

     create user username with password 'password'; 
  4. 使用與Ubuntu用戶相同的名稱和密碼設置postgres用戶,並使他成為postgres超級用戶

     alter user username superuser; 
  5. 創建開發和測試數據庫

     create database projectname_development; create database projectname_test; 
  6. 在數據庫上為用戶授予權限

     grant all privileges on database projectname_development to username; grant all privileges on database projectname_test to username; 

要結束postgresql會話類型\\q

更新用戶的密碼

alter user username with password ‘new password’;
首先,安裝postgresql
gem 'pg'
在psql中創建一個新用戶
 sudo su postgres createuser user_name #Shall the new role be a superuser? (y/n) y 
的Gemfile
 gem 'pg' 

捆綁安裝

development.yml
 development: adapter: postgresql database: app_development pool: 5 username: user_name password: 

您可以點擊此鏈接http://www.cyberciti.biz/faq/howto-add-postgresql-user-account/

創建一個postgres用戶並替換database.yml中的憑據

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM