Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tables in test db are not created for models with app_label #1134

Open
kosdmit opened this issue Jul 29, 2024 · 0 comments
Open

Tables in test db are not created for models with app_label #1134

kosdmit opened this issue Jul 29, 2024 · 0 comments

Comments

@kosdmit
Copy link
Contributor

kosdmit commented Jul 29, 2024

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant