0

运行 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 教程来编写代码。我应该怎么办 ?请帮助我卡住了。有人可以指出我哪里出错了吗?

4

1 回答 1

1

可能是因为 SQL 语句是用逗号分隔的,而不是分号(将它们分隔成离散的命令)?

在 psql 中演示失败:

alter table foo alter x set not null, alter table foo alter y set not null;
ERROR:  syntax error at or near "table"
LINE 1: alter table foo alter x set not null, alter table foo alter ...
                                                    ^
alter table foo alter x set not null; alter table foo alter y set not null;
ALTER TABLE
ALTER TABLE
于 2013-07-18T14:59:12.663 回答