2012-04-01 148 views
2

我剛剛開始學習Rails。 當我嘗試「rake db:migrate」時,發生以下錯誤。rake db:遷移失敗

rake aborted! FATAL:對等身份驗證失敗,用戶「KT1」

似乎有一些錯誤的database.yml,但我不知道如何解決。 請給我一個建議。


非常感謝您的評論和編輯。我使用postgresql(0.13.2)。我的環境如下。 的Ubuntu 11.10 紅寶石1.8.7 的Rails 3.2.3 寶石21年8月1日

的database.yml如下。


# PostgreSQL. Versions 8.2 and up are supported. 
# 
# Install the pg driver: 
# gem install pg 
# On Mac OS X with macports: 
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config 
# On Windows: 
# gem install pg 
#  Choose the win32 build. 
#  Install PostgreSQL and put its /bin directory on your path. 
# 
# Configure Using Gemfile 
# gem 'pg' 
# 
development: 
    adapter: postgresql 
    encoding: unicode 
    database: kt1_development 
    pool: 5 
    username: kt1 
    password: 

    # Connect on a TCP socket. Omitted by default since the client uses a 
    # domain socket that doesn't need configuration. Windows does not have 
    # domain sockets, so uncomment these lines. 
    #host: localhost 
    #port: 5432 

    # Schema search path. The server defaults to $user,public 
    #schema_search_path: myapp,sharedapp,public 

    # Minimum log levels, in increasing order: 
    # debug5, debug4, debug3, debug2, debug1, 
    # log, notice, warning, error, fatal, and panic 
    # The server defaults to notice. 
    #min_messages: warning 

# 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: 
    adapter: postgresql 
    encoding: unicode 
    database: kt1_test 
    pool: 5 
    username: kt1 
    password: 

production: 
    adapter: postgresql 
    encoding: unicode 
    database: kt1_production 
    pool: 5 
    username: kt1 
    password: 

我在空白也試圖與用戶名。那麼錯誤來

rake aborted! 
FATAL: role "kenji" does not exist 

(賢治是我在Ubuntu的用戶名)。

+0

你可以發佈你的'database.yml'嗎?阻止任何敏感數據。你試圖使用哪種數據庫類型(MySQL,PostgreSQL等)? – Alex 2012-04-01 11:57:47

回答

3

您需要先create the user kt1,然後create the database並授予用戶權限。

有一種方法可以讓軌道創建用戶和數據庫,但在PostgreSQL的,最好是用手工做的(恕我直言)

+0

謝謝,你說得對。昨晚我試圖做你的建議,並做到了。這並不容易,因爲我是postgresql的初學者,所以我嘗試了儘可能多的方法,最終我成功了。 – kenzy66 2012-04-03 00:35:42

+0

很高興爲您提供幫助。 :) – 2012-04-03 12:22:22

0

看你的database.yml文件中,將有數據庫適配器,可能是數據庫名稱,用戶名和密碼。

適配器告訴你,你正在使用,sqllite3,mysql2,無論

看看你是否可以手動連接到使用包含在database.yml中的用戶名和密碼的數據庫系統,數據庫系統。一旦找出正確的用戶名和密碼來手動連接,更新database.yml任何更改並再試一次。

8

嘗試修改您的(/etc/postgresql/9.1/main/pg_hba.conf文件這樣,改變了方法讓本地用戶從對等到信任。

# Database administrative login by UNIX sockets 
local all   postgres       trust 

# TYPE DATABASE USER  CIDR-ADDRESS   METHOD 

# "local" is for Unix domain socket connections only 
local all   all        trust 
# IPv4 local connections: 
host all   all   127.0.0.1/32   md5 
# IPv6 local connections: 
host all   all   ::1/128    md5 
+0

是的,這將工作。也許是研究所有其他Postgres身份驗證方法的好時機。 – 2012-12-18 08:34:34

+0

謝謝,夥計!我花了好幾個小時來解決這個問題。你的建議幫助了我! – AntonAL 2013-04-24 11:24:06

0

這發生在應用程序是使用sqlite建立的,然後移植到Postgres以便託管在Heroku上。

運行耙分貝:遷移是爲您提供以下errror

PGError (FATAL: role "rails" does not exist): error message.

和RSpec規格/耙黃瓜失敗,類似的錯誤。

以下步驟似乎解決的問題: createuser -s rails (注:

超級用戶創建軌如果你自己沒有設置爲DB超級用戶,則需要指定不同的DB用戶這樣做,因爲對我來說是CREATEUSER -s軌-U的Postgres)

創建所有者軌數據庫在database.yml中規定:

createdb -O rails kt1(如步驟1,如果您需要指定一個不同的DB用戶來執行此操作,請添加-U )

在這個rake db:migrate之後,rspec spec /和rake cucumber應該會成功運行。