运行 python manage.py migrate 课程时出现此错误。
(edu-venv)vagrant@precise32:/vagrant/projects/kodex$ python manage.py migrate courses
Running migrations for courses:
- Migrating forwards to 0002_add.
> courses:0002_add
FATAL ERROR - The following SQL query failed: ALTER TABLE "courses_courses" ALTER COLUMN "pub_date"
tamp with time zone, ALTER COLUMN "pub_date" SET NOT NULL, ALTER COLUMN "pub_date" DROP DEFAULT;
The error was: column "pub_date" of relation "courses_courses" does not exist
Error in migration: courses:0002_add
DatabaseError: column "pub_date" of relation "courses_courses" does not exist
我的 models.py 文件包含 pub_date 字段
from django.db import models
from embed_video.fields import EmbedVideoField
class Courses(models.Model):
course_name = models.CharField(max_length=150)
pub_date = models.DateTimeField('date published')
def __unicode__(self):
return self.course_name
class Topic(models.Model):
courses = models.ForeignKey(Courses)
topic_name = models.CharField(max_length=255)
content = models.TextField()
video = EmbedVideoField()
published = models.BooleanField(default=True)
def __unicode__(self):
return self.topic_name
我的 admin.py 文件是
from django.contrib import admin
from .models import Courses, Topic
class CoursesAdmin(admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['course_name']}),
('Date Info', {'fields': ['pub_date']}),
]
admin.site.register(Courses, CoursesAdmin)
我指的是官方 Django 文档和 GSWD 教程来编写代码。我应该怎么办 ?请帮助我卡住了。有人可以指出我哪里出错了吗?