Reputation: 356
I changed my models.py file and when running migrate
I get this error. The property is a OneToOneField(). I have tried adding null=True
but that doesn't seem to fix it. It is also weird that even when I comment out the property and run makemigrations
followed by migrate
, I still get that exact same error. Is there a way to fix this? My model looks like this:
class Estimator(Employee):
avg_estimate = models.IntegerField()
class Job(models.Model):
created = models.DateTimeField(auto_now_add=True)
estimator = models.OneToOneField(Estimator, null=True)
address = models.CharField(max_length=100)
completed = models.BooleanField(default=False)
Upvotes: 7
Views: 5735
Reputation: 11879
My guess is that you have created a migration without null=True, that won't migrate, then you created a second migration with null=True.
Running "migrate" will run both migrations in order, so the first one will fail again.
Assuming this is the case, then 1: delete the two most recent files in your migrations folder. (Open them first to confirm that they are creating the migrations as I described before deleting them). 2: run makemigrations again, with null=True in your models.py
This should create the equivalent of the second migration file, without the failing intermediate migration.
Upvotes: 13