Reputation: 1463
Working on a Django 1.7 project, I've had the need to add a field to an existing model.
I added the following: bairro = models.CharField(max_length=200)
Then I ran both commands:
python manage.py makemigrations
python manage.py migrate
And now, tests won't run anymore.
Whenever I run python manage.py test
it gives this error:
django.db.utils.ProgrammingError: column admin_starbeli_salao.bairro does not exist
Which is strange, since if I open the shell I can add objects and the field does work.
What can I do?
Upvotes: 1
Views: 707
Reputation: 1463
It was a problem in one of the migrations.
To find what it was, I dropped my db and tried to run python manage.py migrate
, but the same error ocurred.
Then I noticed one the related models had a default for this model, like this:
def first_my_model():
return MyModel.objects.first().pk if MyModel.objects.first() else 0
It was trying to use that newly added (and not yet existing on the db) field on this call, thus throwing the error.
Upvotes: 1