I have created a series of checks using Django's System check framework.
Some of the checks are used to confirm that fixtures are set up correctly. For example, I have a check that confirms if all users have at least one group.
@register(Tag.database)
def check_users_have_group(app_configs, **kwargs):
errors = []
users = UserModel.objects.all()
for user in users:
if not user.groups.exists():
message = f'{user} has no permission groups set.'
errors.append(
Error(
message,
obj='account',
id=f'check_user_{user.id}_permission_groups'
)
)
return errors
Django's default is to run checks on migration. If I deploy the app without an existing database, then when I run migrate to set up the database the above check will cause a ProgrammingError because the table is not yet created:
django.db.utils.ProgrammingError: relation "accounts_account" does not exist
How can I exclude this test from running on python manage.py migrate? I want to run this after the migration is complete.
OP can configure it to not be so using the flag --skip-checks, like
As mentioned in the previous link
So, OP then has to configure the
requires_system_checksto match what OP wants, because the default value is 'all'.Since OP doesn't want to run
Tags.database, don't include that one in the list. So OP will have something likeIn light of the new specifications (that OP wants to run other database checks), let's get some more context.
Django's system checks are organized using specific built-in tags. Reading more about the database one, we see
This points to what Abdul Aziz Barkat mentions in the comment that
In other words, it's advisable that, for such thing, one creates a custom command. In this other answer I explain how to do so.