Apparently, it's not a good idea to write Django migrations that use the Django ORM wrapper to instantiate fully-hydrated model instances.
Steps to reproduce:
add field to Project model by editing turkle/models.py
run python manage.py makemigrations, which automatically detects the new model field and creates a new migration file (e.g. turkle/migrations/0010_auto_20210406_1305.py)
run python manage.py test --verbosity=3
The test runner runs the migration suite while trying to build the test database, and the migration fails with an sqlite3 error before the test runner can even start the test suite:
Running migrations:
Applying contenttypes.0001_initial... OK (0.003s)
[...]
Applying turkle.0006_copy_can_work_on_permission...Traceback (most recent call last):
File "/Users/charman/opt/anaconda3/envs/turkle/lib/python3.8/site-packages/django/db/backends/utils.py", line 84, in _execute
return self.cursor.execute(sql, params)
File "/Users/charman/opt/anaconda3/envs/turkle/lib/python3.8/site-packages/django/db/backends/sqlite3/base.py", line 383, in execute
return Database.Cursor.execute(self, query, params)
sqlite3.OperationalError: no such column: turkle_project.allotted_assignment_time
This line in migration 0006 is causing Django to try to instantiate Project instances using all of the fields defined in turkle/models.py - but the new field that we added to turkle/models.py does not get added to the database until the new migration (numbered 0010 or higher, based on existing migrations) is run - and the new migration is never run because migration 0006 fails first.
Problem caused by current version of turkle/migrations/0006_copy_can_work_on_permission.py.
Apparently, it's not a good idea to write Django migrations that use the Django ORM wrapper to instantiate fully-hydrated model instances.
Steps to reproduce:
Project
model by editingturkle/models.py
python manage.py makemigrations
, which automatically detects the new model field and creates a new migration file (e.g.turkle/migrations/0010_auto_20210406_1305.py
)python manage.py test --verbosity=3
The test runner runs the migration suite while trying to build the test database, and the migration fails with an sqlite3 error before the test runner can even start the test suite:
which the stack trace reveals is caused by Turkle migration 0006 - turkle/migrations/0006_copy_can_work_on_permission.py#L47:
This line in migration 0006 is causing Django to try to instantiate
Project
instances using all of the fields defined inturkle/models.py
- but the new field that we added toturkle/models.py
does not get added to the database until the new migration (numbered 0010 or higher, based on existing migrations) is run - and the new migration is never run because migration 0006 fails first.