DatabaseError:关系“courses_courses”的列“pub_date”不存在

时间:2013-07-18 09:49:51

标签: django postgresql django-models django-south vagrant

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

1 个答案:

答案 0 :(得分: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