【问题标题】:Using Django ORM inside Tornado, "syncdb" doesn't work在 Tornado 中使用 Django ORM,“syncdb”不起作用
【发布时间】:2013-05-06 09:15:17
【问题描述】:

我在 Tornado 中使用 Django ORM,一切都很顺利,除了“syncdb”不起作用。

这是我的目录结构:

APP_NAME/
    APP_NAME/
        models.py
        settings.py
        __init__.py
    manage.py
    database.db

当我执行python manage.py syncdb 时,消息显示:

Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

并且创建了database.db 文件(我使用的是 splite3),但没有创建表。值得注意的是,如果我在models.py 中引入了一些语法错误,syncdb 会报错,所以似乎syncdb 能够找到我的models.py。只是由于某种原因它没有创建表。

供您参考,这里是我的settings.py(我唯一省略的是SECRET_KEY):

INSTALLED_APPS = (
    'APP_NAME',
)

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'database.db',
    }
}

谢谢。

附:我不确定这是否相关,但我使用的是 Python 3.3.1 + Django 1.5.1 + Tornado 3.0.1

【问题讨论】:

  • 你能给我们看看models.py吗?

标签: python django django-models tornado


【解决方案1】:

如果你这样做了

   django-admin startproject foobar

那么您的设置应该如下所示:

   INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'foobar',
   )

然后

   python manage.py syncdb 

会给你

   Creating tables ...
   Creating table auth_permission
   Creating table auth_group_permissions
   Creating table auth_group
   Creating table auth_user_groups
   Creating table auth_user_user_permissions
   Creating table auth_user
   Creating table django_content_type
   Creating table django_session
   Creating table django_site
   Creating table foobar_mymodel

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-12
    • 2013-03-19
    • 1970-01-01
    • 1970-01-01
    • 2015-07-31
    • 2011-02-13
    • 2015-08-06
    相关资源
    最近更新 更多