Diego Ponciano
Diego Ponciano

Reputation: 1463

Django 1.7 (apparently) not running migrations on manage.py test

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

Answers (1)

Diego Ponciano
Diego Ponciano

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

Related Questions