简体   繁体   English

Django manage.py迁移ImportError

[英]Django manage.py migrate ImportError

I am going through the Django tutorial (version 1.8) and when I try to create the databases for INSTALLED_APPS using the cmd python manage.py migrate 我正在浏览Django教程(版本1.8),当我尝试使用cmd python manage.py migrate为INSTALLED_APPS创建数据库时

I end up getting the following Import Error: 我最终得到以下导入错误:

File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 338, in execute_from_command_line
utility.execute()
File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 303, in execute
settings.INSTALLED_APPS
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 48, in __getattr__
self._setup(name)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
__import__(name)
ImportError: Import by filename is not supported.

My DJANGO_SETTINGS_MODULE links to the correct location ...Django\\mysite\\mysite\\settings.py 我的DJANGO_SETTINGS_MODULE链接到正确的位置...Django\\mysite\\mysite\\settings.py

And here is my settings.py: 这是我的settings.py:

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

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/1.8/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'iv@evv%4@c9v5@oq+o=e%=d#$z1je=o)c98cdbm3ax6h1fr%m7'

# 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_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
)

ROOT_URLCONF = 'mysite.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 = 'mysite.wsgi.application'


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

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.sqlite3',
    'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/New_York'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

STATIC_URL = '/static/'

The error is not actually with INSTALLED_APPS; INSTALLED_APPS实际上没有错误; if you notice, the error is occurring on mod = importlib.import_module(self.SETTINGS_MODULE) , meaning it's unable to import your settings module. 如果您注意到,错误发生在mod = importlib.import_module(self.SETTINGS_MODULE) ,这意味着它无法导入您的设置模块。

The problem, in this case, is that your DJANGO_SETTINGS_MODULE needs to be a dotted Python path, rather than a filesystem path. 在这种情况下,问题是你的DJANGO_SETTINGS_MODULE需要是一个虚线的Python路径,而不是文件系统路径。 My best guess for what you need is: 我对你需要的最好的猜测是:

DJANGO_SETTINGS_MODULE="mysite.mysite.settings"
ImportError: Import by filename is not supported.

Looks like you're trying to import an app and specify the filename instead of the name. 看起来您正在尝试导入应用并指定文件名而不是名称。 Could you post the settings.py? 你可以发布settings.py吗? You have to write something like this: 你必须写这样的东西:

INSTALLED_APPS = (

... snip ...

   'polls',
)

and not something like this: 而不是这样的:

INSTALLED_APPS = (

... snip ...

   'polls.py',
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM