无法打开数据库文件

时间:2014-08-05 20:04:17

标签: python mysql django

我正在尝试将我的django站点设置为在Web服务器上运行。我试图将其设置为使用mysql数据库运行。但是,我收到错误操作错误:无法打开数据库文件。互联网上的大多数资源都指向在尝试使用sqlite时导致此错误。我不确定我做错了什么。这是我的settings.py文件的相关部分:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

BASE_SITE_URL = ...

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = ...

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

TEMPLATE_DEBUG = True

ALLOWED_HOSTS = []

TEMPLATE_CONTEXT_PROCESSORS = (
    "django.contrib.auth.context_processors.auth",
    "django.core.context_processors.debug",
    "django.core.context_processors.i18n",
    "django.core.context_processors.media",
    "django.core.context_processors.request",
)

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'list_app',
)

MIDDLEWARE_CLASSES = (
    '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',

    'django_cas.middleware.CASMiddleware',
    'django.middleware.doc.XViewMiddleware',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'django_cas.backends.CASBackend'
)

ROOT_URLCONF = 'list_site.urls'

WSGI_APPLICATION = 'list_site.wsgi.application'

CAS_SERVER_URL = ...

CAS_LOGOUT_COMPLETELY = True

CAS_REDIRECT_URL = BASE_SITE_URL + '/lists/index'

CAS_ADMIN_PREFIX = BASE_SITE_URL + '/admin'

TEMPLATE_DIRS = [os.path.join(BASE_DIR, 'templates')]


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

DATABASES = {
    'default': {
        'ENGINE':   'mysql.connector.django',
        'NAME':     'maillists',
        'USER':     'wasingej',
        'PASSWORD': '...', 
        'HOST':     '...',
        'PORT':     '3306',
    }
}

# Internationalization
# https://docs.djangoproject.com/en/1.6/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/1.6/howto/static-files/

STATIC_URL = '/static/'

2 个答案:

答案 0 :(得分:0)

对于MySQL我使用

'ENGINE': 'django.db.backends.mysql', 

以及数据库名称:只提供名称(“ maillists ”) - 而不是(ny)路径

答案 1 :(得分:0)

您已为数据库ENGINE部件定义了错误。对于MySQL,它应该是

ENGINE: 'django.db.backends.mysql',

改变它将起作用