I have a class as following:
class Mission(models.Model):
taxi = ForeignKey(Taxi, null=True, blank=True, unique=True, related_name="mission")
passenger = ForeignKey(Passenger, null=True, blank=True, unique=True, related_name="mission")
Now there's a method in the Class Taxi:
def turn_free(self):
....
self.mission_set.clear()
passenger.mission_set.clear() # passenger has been fetched
The first attempt to clear mission开发者_运维知识库 in Taxi proceed successfully, but the second one for the passenger reports an error: ccst_mission.passenger_id may not be NULL
Could someone help me?
Make sure your database has been updated properly.
For example, if you originally had (without specifying null=True)
passenger = Foreignkey(Passsenger, unique=True)
And added the null=True later on, a regular syncdb will not update that column to allow null.
If any of that sounds familiar, try doing an sqlclear on the app (or deleting the database entirely) then doing a fresh syncdb.
精彩评论