2013-07-18 83 views
0

我在運行python manage.py遷移課程時遇到此錯誤。DatabaseError:關係「courses_courses」的列「pub_date」不存在

(edu-venv)[email protected]:/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

難道是因爲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 
相關問題