2014-01-30 30 views
2

KeyError:u'name'。Django south migration causes KeyError:u'name'

下面是相關模式,全面models.py可here

from django.db import models 
from django.contrib.auth.models import User 
from sorl.thumbnail import ImageField 
import string,random,datetime 


class Property(models.Model): 
    name = models.CharField(max_length = 200)   
    inspected_by = models.ForeignKey(User,null = True, blank = True) 
    #inspection_date = models.CharField(max_length = 200,null=True,blank = True) 
    lease = models.ForeignKey('PropertyLease') 
    occupancy = models.ForeignKey('PropertyOccupancy') 
    owner = models.ForeignKey('PropertyOwner') 
    property_type = models.ForeignKey('PropertyType') 
    cost = models.ForeignKey('PropertyCost', null = True, blank = True)  
    floor_plate_area = models.IntegerField(null = True,blank = True, verbose_name="Total floor plate area (In sqft)")  
    total_available_area = models.IntegerField(null = True,blank = True, verbose_name="Total available area (In sqft)") 
    special_note = models.TextField(null = True, blank = True)  



    residential = models.BooleanField(default=False)  
    commercial = models.BooleanField(default = False) 


    is_active = models.BooleanField(default=True) 
    datetime = models.DateTimeField(auto_now_add=True) 
    last_updated = models.DateTimeField(null = True, blank = True)  
    def save(self,*args, **kwargs): 
     self.last_updated = datetime.datetime.now() 

    if (self.is_active == False): 

     if(self.property_type.name=="Building"): 

      bld = PropertyBuilding.objects.get(property=self) 

      floors = PropertyFloor.objects.filter(building=bld) 

      for floor in floors: 
       units = PropertyUnit.objects.filter(floor=floor) 
       floor.property.is_active=False 
       floor.property.save() 
       for unit in units: 
        unit.property.is_active=False 
        unit.property.save() 
    if (self.property_type.name=="SEZ"): 
     blds = PropertyBuilding.objects.filter(parcel__estate=self) 
     for bld in blds: 
      floors = PropertyFloor.objects.filter(building=bld) 
      bld.property.save() 
      for floor in floors: 
       units = PropertyUnit.objects.filter(floor=floor) 
       floor.property.save() 
       for unit in units: 
        unit.property.save() 
    elif (self.property_type.name=="Building"): 
     floors = PropertyFloor.objects.filter(building=self) 

     for floor in floors: 
       units = PropertyUnit.objects.filter(floor=floor) 
       floor.property.save() 
       for unit in units: 
        unit.property.save()  
    elif (self.property_type.name=="Floor"):   
       units = PropertyUnit.objects.filter(floor=self) 

       for unit in units: 
        unit.property.save()   

    super(Property, self).save(*args, **kwargs) 

我 在這個模型中,我只是要添加哪些已被註釋掉的單個字段。

沒有添加字段的第一次遷移沒有問題。但第二次遷移帶來的變化給了錯誤。我究竟做錯了什麼?

添加一些traceback

+0

你執行了哪個命令?在南方,你必須爲第一次遷移執行「--initial」,而在下一次遷移時執行「--auto」。另外,有時候,你從你的第一次遷移中改變你的數據庫,並且(如果你沒有關於數據庫的信息),我建議你刪除所有的表並且再次進行遷移 – AlvaroAV

+0

還有另外一個叫做convert_to_south的命令,你說了什麼。然後第二個命令是--auto – user3190607

回答

1

這個問題發生在南部0.7.3。請升級到南0.8。它會解決問題。