抽象模型错误

时间:2016-03-02 10:07:17

标签: python django django-models

我在“添加Easy Admin电子邮件,帮助程序,站点地图等”一章中有关于抽象模型的问题(hello web app中间书) 这是我的models.py代码:

from django.contrib.auth.models import User
from django.db import models

class Timestamp(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)

    class Meta:
        abstract = True

class Thing(Timestamp):
    name = models.CharField(max_length=225)


class Thing(models.Model):
    name = models.CharField(max_length=225)
    description = models.TextField()
    slug = models.SlugField(unique=True)
    user = models.OneToOneField(User, blank=True, null=True)
    def get_absolute_url(self):
        return "/things/%s/" % self.slug


class Social(models.Model):
    SOCIAL_TYPES = (
        ('twitter','Twitter'),
        ('facebook','Facebook'),
        ('pinterest','Pinterest'),
        ('instagram','Instagram'),
    )
    network = models.CharField(max_length=255, choices=SOCIAL_TYPES)
    username = models.CharField(max_length=255)
    thing = models.ForeignKey(Thing,related_name="social_accounts")

    class Meta:
        verbose_name_plural = "Social media links"

当我跑

$python manage.py makemigrations
$python manage.py migrate

错误消息显示:

/helloApp/venv/lib/python2.7/site-packages/django/db/models/base.py:309: RuntimeWarning: Model 'collection.thing' was already registered. Reloading models is not advised as it can lead to inconsistencies, most notably with related models.
  new_class._meta.apps.register_model(new_class._meta.app_label, new_class)

No changes detected

没有像书中那样显示:

You are trying to add a non-nullable field 'added' to thing without a defaul,,,,,,,

任何答案都会非常感谢你!

0 个答案:

没有答案