0

我是 django 的新手。我一直在关注 Practical Django Projects 这本书来学习它。正如书中提到的,我正在创建一个博客。我已经按照编写入口模型的所有步骤进行了操作。当尝试从管理界面添加条目时出现错误

  DatabaseError at /adminlebron/entry/add/
  table lebron_entry has no column named slug

经过一番搜索后,我发现我在完全创建模型之前运行了 syncdb,并且从 django 文档中我发现 Syncdb 不会更改现有表。之后我找到了 South(http://south.aeracode.org/)并尝试使用它,但我仍然遇到同样的错误。

这是我的入门模型

class Entry(models.Model):
    STATUS_CHOICES = (
    (1,'Live'),
    (2,'Draft'),
    )
    title = models.CharField(max_length=250)
        excerpt = models.TextField(blank=True)
    body = models.TextField()
    pub_date = models.DateTimeField(default=datetime.datetime.now)
    slug = models.SlugField(help_text="Slug")
    author = models.ForeignKey(User)
    enable_comments = models.BooleanField(default=True)
    featured = models.BooleanField(default=False)
    status = models.IntegerField(choices=STATUS_CHOICES,default=1)
    categories = models.ManyToManyField(Category)
    tags = TagField()
    excerpt_html = models.TextField(editable=False,blank=True)
    body_html = models.TextField(editable=False,blank=True)

    def save(self):
        self.body_html = markdown(self.body)
        if self.excerpt:
            self.excerpt_html = markdown(self.excerpt)
        super(Entry,self).save()

    class Meta:
        verbose_name_plural = "Entries"
            ordering = ['-pub_date']

    class Admin:
        pass

    def __unicode__(self):
        return self.title

    def get_absolute_url(self):
        return "/weblog/%s/%s/" %     (self.pub_date.strftime("%Y/%b/%d").lower(),self.slug)

这是 sqlall 的输出

BEGIN;
CREATE TABLE "lebron_category" (
    "id" integer NOT NULL PRIMARY KEY,
    "title" varchar(250) NOT NULL,
    "slug" varchar(50) NOT NULL UNIQUE,
    "description" text NOT NULL
)
;
CREATE TABLE "lebron_entry_categories" (
    "id" integer NOT NULL PRIMARY KEY,
    "entry_id" integer NOT NULL,
    "category_id" integer NOT NULL REFERENCES "lebron_category" ("id")
    UNIQUE ("entry_id", "category_id")
)
;
CREATE TABLE "lebron_entry" (
    "id" integer NOT NULL PRIMARY KEY,
    "title" varchar(250) NOT NULL,
    "excerpt" text NOT NULL,
    "body" text NOT NULL,
    "pub_date" datetime NOT NULL,
    "slug" varchar(50) NOT NULL,
    "author_id" integer NOT NULL REFERENCES "auth_user" ("id"),
    "enable_comments" bool NOT NULL,
    "featured" bool NOT NULL,
    "status" integer NOT NULL,
    "tags" varchar(255) NOT NULL,
    "excerpt_html" text NOT NULL,
    "body_html" text NOT NULL
)
;
CREATE INDEX "lebron_entry_56ae2a2a" ON "lebron_entry" ("slug");
CREATE INDEX "lebron_entry_337b96ff" ON "lebron_entry" ("author_id");
COMMIT;

看来柱塞毕竟在表中。我不想重新创建数据库有没有其他方法可以纠正这个问题?我的应用程序的名称是勒布朗

4

0 回答 0