pytest-django
pytest-django copied to clipboard
Tables in test db are not created for models with app_label
I use --no-migrations
option to create a test database by inspecting all models. This usually works well, but I got a problem with django models that have an app_label
meta attr. Such models are ignored and do not create automatically.
Model for example:
class SAPDepartment(models.Model):
class Meta:
app_label = 'structure'
sap_name = models.CharField(max_length=150, null=False, blank=False)
sap_id = models.IntegerField()
up_dep = models.ForeignKey('self', related_name='low_dep', on_delete=models.SET_NULL, null=True)
Tables list if we do not use app_label
(sapdepartment
table exists):
test_procurement_db=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------------------------------------+-------+----------
...
public | django_content_type | table | postgres
public | django_session | table | postgres
public | info_db_sapdepartment | table | postgres
public | info_db_sapemployee | table | postgres
public | material_analogue_employee | table | postgres
...
(27 rows)
Tables list if we use app_label
(there is not sapdepartment
table):
test_procurement_db=# \dt
List of relations
Schema | Name | Type | Owner
--------+---------------------------------------+-------+----------
public | auth_group | table | postgres
public | auth_group_permissions | table | postgres
public | auth_permission | table | postgres
public | auth_user | table | postgres
public | auth_user_groups | table | postgres
public | auth_user_user_permissions | table | postgres
public | django_admin_log | table | postgres
public | django_celery_beat_clockedschedule | table | postgres
public | django_celery_beat_crontabschedule | table | postgres
public | django_celery_beat_intervalschedule | table | postgres
public | django_celery_beat_periodictask | table | postgres
public | django_celery_beat_periodictasks | table | postgres
public | django_celery_beat_solarschedule | table | postgres
public | django_content_type | table | postgres
public | django_session | table | postgres
public | material_analogue_employee | table | postgres
public | material_analogue_group | table | postgres
public | material_analogue_group_members | table | postgres
public | material_analogue_lot | table | postgres
public | material_analogue_materialrequest | table | postgres
public | material_analogue_materialrequestfile | table | postgres
public | material_analogue_procurer | table | postgres
public | material_analogue_requeststatus | table | postgres
public | material_analogue_subsection | table | postgres
public | material_analogue_supplier | table | postgres
(25 rows)