Django不会为抽象模型生成数据库表。您应该从抽象类继承,或者简单地删除Meta类中的
我是Django的新手,无法将任何模型添加到我的DB中??好的,这是投资组合模型:
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',
)
谢谢:)
abstract = True
行。