【问题标题】:django syncdb fails and does not know my moduledjango syncdb 失败并且不知道我的模块
【发布时间】:2015-07-21 08:54:07
【问题描述】:

我在 64 位 Windows 7 和 Django 1.8.3 中使用 64 位 Python 3.4。 我创建了一个名为 blog 的模块并在 settings.py 中编辑了 INSTALLED_APP 部分,如下所示:

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

但是当我运行“python manage.py syncdb”时出现以下错误:

Traceback (most recent call last):
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\apps\config.py", line 114, in create
    cls = getattr(mod, cls_name)

AttributeError: 'module' object has no attribute 'blog'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\core\management\__init__.py", line 338, in execute_from_co
mmand_line
utility.execute()
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\core\management\__init__.py", line 312, in execute
    django.setup()
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\__init__.py", line 18, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\apps\registry.py", line 85, in populate
    app_config = AppConfig.create(entry)
  File "D:\python-3.4.3.amd64\lib
\site-packages\django\apps\config.py", line 119, in create
    import_module(entry)
  File "D:\python-3.4.3.amd64\lib
\importlib\__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked

ImportError: No module named 'mysite01.blog'

【问题讨论】:

  • 你到底想做什么?
  • 在 INSTALLED_APPS 中将 mysite01.blog 重命名为博客
  • 好吧,谢谢@GeoJacob,它解决了我的问题。

标签: python django


【解决方案1】:

感谢@GeoJacob,通过将 settings.py 编辑为:

INSTALLED_APPS = (
...
'blog',)

但为了在 db 中创建模型表,此命令在 syncdb 之前是必需的:

>python manage.py makemigrations

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-28
    • 2010-11-20
    • 1970-01-01
    • 1970-01-01
    • 2021-07-06
    • 1970-01-01
    相关资源
    最近更新 更多