문제

KeyError: u'name'.

Here is the relevant model, the full models.py is available 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)

I In this model I am simply going to add a single field which has been commented out.

The first migration without adding the field goes fine. But the second migration with the field change gives the error. What am I doing wrong?

Adding some more traceback

도움이 되었습니까?

해결책

This issue happens in south 0.7.3. Please upgrade it to south 0.8. It will solve the problem.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top