2017-01-20 116 views
1

我在amazon web上設置django,並且遇到連接到數據庫的問題。我創建的數據庫,並查看它的存在:Django錯誤:django.db.utils.OperationalError:致命錯誤:用戶對等身份驗證失敗

postgres=# CREATE DATABASE kbuzz; 
ERROR: database "kbuzz" already exists 

和用戶也存在

postgres=# SELECT 1 FROM pg_roles WHERE rolname='kbuzz_web' 
postgres-# ; 
?column? 
---------- 
     1 
(1 row) 

這裏是我的數據庫設置

DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. 
     'NAME': 'kbuzz',      # Or path to database file if using sqlite3. 
     'USER': 'kbuzz_web', 

          # Not used with sqlite3. 
     'PASSWORD': '<hidden>',     # Not used with sqlite3. 
     'HOST': 'localhost',      # Set to empty string for localhost. Not used with sqlite3. 
     'PORT': '',      # Set to empty string for default. Not used with sqlite3. 
    } 
} 

當我嘗試的runserver我得到一個錯誤

(djangoenv) [email protected]:~/webapps/kenyabuzz$ python manage.py runserver 
Performing system checks... 

System check identified some issues: 

WARNINGS: 
?: (1_6.W001) Some project unittests may not execute as expected. 
    HINT: Django 1.6 introduced a new default test runner. It looks like this project was generated using Django 1.5 or earlier. You should ensure your tests are all running & behaving as expected. See https://docs.djangoproject.com/en/dev/releases/1.6/#new-test-runner for more information. 

System check identified 1 issue (0 silenced). 
Unhandled exception in thread started by <function wrapper at 0x7f222281a320> 
Traceback (most recent call last): 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/utils/autoreload.py", line 222, in wrapper 
    fn(*args, **kwargs) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 107, in inner_run 
    self.check_migrations() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/core/management/commands/runserver.py", line 159, in check_migrations 
    executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS]) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 17, in __init__ 
    self.loader = MigrationLoader(self.connection) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 48, in __init__ 
    self.build_graph() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/migrations/loader.py", line 179, in build_graph 
    self.applied_migrations = recorder.applied_migrations() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 59, in applied_migrations 
    self.ensure_schema() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/migrations/recorder.py", line 49, in ensure_schema 
    if self.Migration._meta.db_table in self.connection.introspection.get_table_list(self.connection.cursor()): 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 167, in cursor 
    cursor = utils.CursorWrapper(self._cursor(), self) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 138, in _cursor 
    self.ensure_connection() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection 
    self.connect() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__ 
    six.reraise(dj_exc_type, dj_exc_value, traceback) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 133, in ensure_connection 
    self.connect() 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/__init__.py", line 122, in connect 
    self.connection = self.get_new_connection(conn_params) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 134, in get_new_connection 
    return Database.connect(**conn_params) 
    File "/home/ubuntu/webapps/djangoenv/local/lib/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect 
    conn = _connect(dsn, connection_factory=connection_factory, async=async) 
django.db.utils.OperationalError: FATAL: Peer authentication failed for user "kbuzz_web" 

回答

1

On pg_hb a.conf改變

# TYPE DATABASE USER ADDRESS METHOD 
local all  all   peer 

# TYPE DATABASE USER ADDRESS METHOD 
local all  all   md5 

,並重新啓動PostgreSQL服務器

+0

這裏很可能是位於服務器 –

+1

的/ etc/PostgreSQL的/ /主/ pg_hba上的文件。 CONF – Anoop

相關問題