You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TLDR of error:
Add a migration that removes a field using the django makemigrations flow. Running migrations using django is fine, no errors returned.
Running pipenv run pytest sample/tests.py returns the error ERROR sample/tests.py::TestModelTestCase::test_example - django.db.utils.ProgrammingError: column sample_testmodel.original_text does not exist.
I run into an error when testing a django application with pytest, more specifically when running tests if I have done a migration that removes a field used in an earlier migration. Doing so outside of tests gives no error.
To reproduce:
models.py
fromdjango.dbimportmodelsclassTestModel(models.Model):
# We started with this field, but now longer need it# original_text = models.CharField(max_length=255)# We added this field and then moved over to itnew_text=models.CharField(max_length=511)
This is a minimal setup to reproduce the error. Now when running pipenv run pytest sample/tests.py I get the error ERROR sample/tests.py::TestModelTestCase::test_example - django.db.utils.ProgrammingError: column sample_testmodel.original_text does not exist. In the error stack it clearly states the following:
sample/migrations/0002_testmodel_new_text.py:9: in move_text_to_other_field_and_append_new
for test_model in TestModel.objects.all():
And then:
self = <django.db.backends.utils.CursorWrapper object at 0x7f3e53a40e80>, sql = 'SELECT "sample_testmodel"."id", "sample_testmodel"."original_text", "sample_testmodel"."new_text" FROM "sample_testmodel"', params = ()
ignored_wrapper_args = (False, {'connection': <django.db.backends.postgresql.base.DatabaseWrapper object at 0x7f3e5d7e5d90>, 'cursor': <django.db.backends.utils.CursorWrapper object at 0x7f3e53a40e80>})
def _execute(self, sql, params, *ignored_wrapper_args):
self.db.validate_no_broken_transaction()
with self.db.wrap_database_errors:
if params is None:
# params default might be backend specific.
return self.cursor.execute(sql)
else:
> return self.cursor.execute(sql, params)
E django.db.utils.ProgrammingError: column sample_testmodel.original_text does not exist
E LINE 1: SELECT "sample_testmodel"."id", "sample_testmodel"."original...
E ^
../../../.local/share/virtualenvs/sprancher-wR5ufyMh/lib/python3.8/site-packages/django/db/backends/utils.py:84: ProgrammingError
This has been bugging me for a long time. It only goes wrong with the tests. Commenting out the RunPython line in 0002 has worked, but is obviously not a long term solution. Running the tests before adding 0003 outputs green lights, no issues up to that point. The order of execution seems incorrect to me or something, but I can't really wrap my head around it.
My question is, why does this happen and how do I prevent this from happening?
The text was updated successfully, but these errors were encountered:
TLDR of error:
Add a migration that removes a field using the django makemigrations flow. Running migrations using django is fine, no errors returned.
Running
pipenv run pytest sample/tests.py
returns the errorERROR sample/tests.py::TestModelTestCase::test_example - django.db.utils.ProgrammingError: column sample_testmodel.original_text does not exist
.I run into an error when testing a django application with pytest, more specifically when running tests if I have done a migration that removes a field used in an earlier migration. Doing so outside of tests gives no error.
To reproduce:
models.py
migrations/0001_initial.py
migrations/0002_testmodel_new_text.py
migrations/0003_remove_testmodel_original_text.py
tests.py
This is a minimal setup to reproduce the error. Now when running
pipenv run pytest sample/tests.py
I get the errorERROR sample/tests.py::TestModelTestCase::test_example - django.db.utils.ProgrammingError: column sample_testmodel.original_text does not exist
. In the error stack it clearly states the following:And then:
This has been bugging me for a long time. It only goes wrong with the tests. Commenting out the
RunPython
line in 0002 has worked, but is obviously not a long term solution. Running the tests before adding 0003 outputs green lights, no issues up to that point. The order of execution seems incorrect to me or something, but I can't really wrap my head around it.My question is, why does this happen and how do I prevent this from happening?
The text was updated successfully, but these errors were encountered: