vivek munjal
vivek munjal

Reputation: 21

Unit test failing due to migration error caused by loaddata in django

My unit test are failing with the following error

django.db.utils.OperationalError: Problem installing fixture '/Users/vivekmunjal/chargepoint/code/Installer/api/installer/fixtures/country.json': Could not load installer.Country(pk=1): (1054, "Unknown column 'display_order' in 'field list'")

Basically one of my migrations is loading data in country model from a fixture, but the model has added some extra fields in them, so when the migrations runs it try to insert a column which is not yet created and fails. Can anyone suggest any remedy for the same?

Upvotes: 0

Views: 219

Answers (1)

Nikita Davydov
Nikita Davydov

Reputation: 957

Your database and code are inconsistent at the moment of your migration loading. You should split these migrations because now it happens during one transaction and your changes aren't committed when you trying load the fixture. In general, it's bad practice to load fixtures during migrations. I advise you to implement the script which you will run after all migrations passed.

Upvotes: 3

Related Questions