【发布时间】:2014-06-11 17:58:24
【问题描述】:
我是 Django 新手,无法将任何模型添加到我的数据库中?? 好的,这是投资组合模型:
from django.db import models
from core.models import Unit
# Create your models here.
class Portfolio(models.Model):
"""
Generic class to portfolios
"""
name = models.CharField(_('Name'), max_length=255)
youtube_id = models.CharField(_('Youtube_id'), max_length=255)
url_doc = models.CharField(_('Url_doc'), max_length=255)
data = models.TextField()
unit = models.ForeignKey(Unit, verbose_name=_('Unit'), null=True, blank=True, related_name='portfolios')
comment = models.TextField(_('Comment'), blank=True)
class Meta:
verbose_name = _('Portfolio')
verbose_name_plural = _('Portfolios')
ordering = [('id')]
abstract = True
def __unicode__(self):
return u'%s' % (self.name)
这是 python manage.py syncdb 的结果:
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
一切正常,但表没有创建!!!!
这是setting.py文件:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'timtec.sqlite', # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': '',
'PASSWORD': '',
'HOST': '',
# Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
'PORT': '',
# Set to empty string for default.
}
}
INSTALLED_APPS = (
'django_extensions',
'south',
'pipeline',
'suit',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.flatpages',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
'django.contrib.admindocs',
'rest_framework',
'rosetta',
'autoslug',
'core',
'accounts',
'activities',
'administration',
'forum',
'course_material',
'notes',
'reports',
'portfolio',
'metron',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.facebook',
'django_markdown',
# raven has to be the last one
'raven.contrib.django.raven_compat',
)
谢谢:)
【问题讨论】:
-
您是否将包含 Portfolio 的应用程序包含到您的设置 INSTALLED_APPS 中?
-
确保名称、youtube_id 等是缩进的(不确定这是否只是堆栈溢出格式错误)。
-
是的,我已将投资组合应用添加到 setting.py 文件中??
-
Hy Kyle R,不,这不是缩进错误,我很确定
-
您确定您检查的是正确的数据库吗?您是否正确设置了数据库设置?
标签: python django sqlite model