2017-03-28 65 views
2

在第一個:對於這個重複抱歉,但其他類似的問題相關的這個問題總是告訴同樣的方法來解決這個問題,但沒有適用於我。我試圖從sqlite的遷移數據庫向PostgreSQL ...所以我鍵入:postgresql:FATAL:密碼驗證失敗,用戶「道格拉斯」

sudo -u postgres psql 
postgres=# ALTER USER postgres WITH PASSWORD 'newpassword'; 

和輸出回: 「ALTER ROLE

但是當我鍵入「蟒蛇manage.py遷移「我總是收到相同的錯誤:

django.db.utils.OperationalError: FATAL: password authentication failed for user "douglas"

settings.py:

# Application definition 

INSTALLED_APPS = [ 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.messages', 
    'django.contrib.staticfiles', 
    'app', 
] 

MIDDLEWARE = [ 
    'django.middleware.security.SecurityMiddleware', 
    'django.contrib.sessions.middleware.SessionMiddleware', 
    'django.middleware.common.CommonMiddleware', 
    'django.middleware.csrf.CsrfViewMiddleware', 
    'django.contrib.auth.middleware.AuthenticationMiddleware', 
    'django.contrib.messages.middleware.MessageMiddleware', 
    'django.middleware.clickjacking.XFrameOptionsMiddleware', 
] 

ROOT_URLCONF = 'site_.urls' 

TEMPLATES = [ 
    { 
     'BACKEND': 'django.template.backends.django.DjangoTemplates', 
     'DIRS': [], 
     'APP_DIRS': True, 
     'OPTIONS': { 
      'context_processors': [ 
       'django.template.context_processors.debug', 
       'django.template.context_processors.request', 
       'django.contrib.auth.context_processors.auth', 
       'django.contrib.messages.context_processors.messages', 
      ], 
     }, 
    }, 
] 

WSGI_APPLICATION = 'site_.wsgi.application' 


# Database 
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases 

""" 
DATABASES = { 
    #'default': { 
    # 'ENGINE': 'django.db.backends.sqlite3', 
    # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), 
    #} 
    'default': dj_database_url.config(default='postgres://localhost:5432/postgres_db_name'), 
} 
""" 


DATABASES = { 
    'default': { 
     'ENGINE': 'django.db.backends.postgresql', 
     'NAME': 'douglas_db', 
     'USER': 'douglas', 
     'PASSWORD': 'vamointer', 
     'HOST': '127.0.0.1', 
     'PORT': '5432', 
    } 
} 
# Password validation 
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators 

#DATABASES = {'default': dj_database_url.config(default='postgres://127.0.0.1:5432/postgres_db_name')} 

AUTH_PASSWORD_VALIDATORS = [ 
    { 
     'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 
    }, 
    { 
     'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 
    }, 
] 


# Internationalization 
# https://docs.djangoproject.com/en/1.10/topics/i18n/ 

LANGUAGE_CODE = 'pt-br' 

TIME_ZONE = 'America/Sao_Paulo' 

USE_I18N = True 

USE_L10N = True 

USE_TZ = True 


# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.10/howto/static-files/ 

STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(BASE_DIR, 'static') 

PS:當我運行 'ALTER USER的Postgres WITH PASSWORD' 我把在settings.py定義相同的密碼。

謝謝!

+0

錯誤提到了用戶帳戶user,但你的alter語句正在改變用戶postgres的密碼。最後,你的settings.py引用另一個用戶; 'douglas'。你真的想使用哪一個用戶,並且你是否正在運行引用這個用戶的命令? – Shadow

+2

夠公平的。那麼SQL查詢呢?你應該運行'ALTER USER douglas WITH PASSWORD'vamointer';' – Shadow

+0

對不起,我不明白你的意思。在嘗試運行遷移之前,您是否運行了我在postgres數據庫上編寫的查詢? – Shadow

回答

3

您正在運行的SQL與您嘗試使用的用戶不匹配。

您需要create the user如果不存在

CREATE USER douglas WITH PASSWORD 'vamointer'; 

,或者如果它確實存在,而不是更改用戶密碼。

ALTER USER douglas WITH PASSWORD 'vamointer'; 

一旦你完成了,你應該有更多的運氣。您也可能需要assign permissions to that user

+0

地獄是啊!這是工作,感謝你的耐心和關注的兄弟! –

+1

不用擔心:)這是關於提取正確的信息...:P – Shadow