当我在Windows 7上运行CMD命令时:
我已经安装了postgresql 10,并在我的django的
我想要在Windows7上使用CMD从python django应用程序访问postgresql数据库。
我正在使用Windows 7,python 3.7.1;postgresql 10;django 2.1.5。我尝试了几次搜索解决方案,但是没有找到相关的解决方案。我已经使用pgAdmin 4 v4创建了我的postgresql数据库,但是无法使用CMD命令在Windows 7上访问它以执行诸如以下命令的操作:
当我运行时:
相反,我得到了:
python manage.py makemigrations
我遇到了一个错误:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend. Try using 'django.db.backends.XXX' where XXX is one of : 'mysql', 'oracle', 'sqlite3'
我已经安装了postgresql 10,并在我的django的
setting.py
中按照文档说明设置了postgresql。我想要在Windows7上使用CMD从python django应用程序访问postgresql数据库。
我正在使用Windows 7,python 3.7.1;postgresql 10;django 2.1.5。我尝试了几次搜索解决方案,但是没有找到相关的解决方案。我已经使用pgAdmin 4 v4创建了我的postgresql数据库,但是无法使用CMD命令在Windows 7上访问它以执行诸如以下命令的操作:
python manage.py showmigrations/makemigrations/migrate
所有的错误都与主题中提到的一样。
settings.py文件从这里开始...
"""
Django settings for my_sample project.
Generated by 'django-admin startproject' using Django 2.1.5.
For more information on this file, see
https://docs.djangoproject.com/en/2.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.1/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'secret key string was here but now is purposely removed'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
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 = 'my_sample.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 = 'my_sample.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'my_sample',
'USER': 'postgres',
'PASSWORD': 'my_password',
'HOST':'localhost',
'PORT': '5432',
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
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/2.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/static/'
#settings.py file ends here...
#manage.py file starts here...
#!/usr/bin/env python
import os
import sys
if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_sample.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
#manage.py file ends here...
当我运行时:
python manage.py migrate
I expect to get:
Running migrations:
No migrations to apply.
相反,我得到了:
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.postgresql' isn't an available database backend. Try using 'django.db.backends.XXX' where XXX is one of : 'mysql', 'oracle', 'sqlite3'