我是django的新手。我一直在关注实用Django项目以学习它。 我正在创建一本书中提到的博客。我已经按照编写Entry模型的所有步骤进行操作。当尝试从管理界面添加条目时,我收到错误
DatabaseError at /adminlebron/entry/add/
table lebron_entry has no column named slug
在搜索了一下之后,我发现在完全创建模型之前我运行了syncdb,并且从django文档中我发现Syncdb不会改变现有的表。之后我找到了南(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;
看来,表格中的柱子毕竟是在那里。 我不想重新创建db有没有其他方法来纠正这个?我的应用程序的名称是lebron