在第一個:對於這個重複抱歉,但其他類似的問題相關的這個問題總是告訴同樣的方法來解決這個問題,但沒有適用於我。我試圖從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定義相同的密碼。
謝謝!
錯誤提到了用戶帳戶user,但你的alter語句正在改變用戶postgres的密碼。最後,你的settings.py引用另一個用戶; 'douglas'。你真的想使用哪一個用戶,並且你是否正在運行引用這個用戶的命令? – Shadow
夠公平的。那麼SQL查詢呢?你應該運行'ALTER USER douglas WITH PASSWORD'vamointer';' – Shadow
對不起,我不明白你的意思。在嘗試運行遷移之前,您是否運行了我在postgres數據庫上編寫的查詢? – Shadow