Antonio Bojorquez
Antonio Bojorquez

Reputation: 11

KeyError: 'skip_checks' on heroku run python manage.py migrate_schemas --shared

After deployment in Heroku a Django app, I run a command as follows:

heroku python manage.py migrate_schemas --shared

to create shared tables in DB, when using multitenancy (Django-tenant-schemas), and that migration throws this error:

File "/app/.heroku/python/lib/python3.10/site-packages/tenant_schemas/migration_executors/base.py", line 58, in run_migrations run_migrations(self.args, self.options, self.codename, public_schema_name) File "/app/.heroku/python/lib/python3.10/site-packages/tenant_schemas/migration_executors/base.py", line 31, in run_migrations MigrateCommand(stdout=stdout, stderr=stderr).execute(*args, **options) File "/app/.heroku/python/lib/python3.10/site-packages/django/core/management/base.py", line 365, in execute if self.requires_system_checks and not options['skip_checks']: KeyError: 'skip_checks'

Django v = 3.0

Any idea of how fix this error?

Upvotes: 1

Views: 341

Answers (1)

sandpat
sandpat

Reputation: 1485

I got the same error while updating to Django 4.1.1. After much effort, I found the following solution. You need to write a custom command to skip the checks:

from django_tenants.management.commands.migrate_schemas import Command as BaseCommand

class Command(BaseCommand):
    help = (
        "Updates database schema. Manages both apps with migrations and those without."
    )
    requires_system_checks = []
    
    def add_arguments(self, parser):
        super().add_arguments(parser)
        parser.add_argument(
            "--skip-checks",
            action="store_true",
            dest="skip_checks",
            default=False,
            help="Skip the checks.",
        )

Put it in a python file, say, migrate_tenant_schemas.py. Then to run the migration step, call:

python3 manage.py migrate_tenant_schemas

Also note that the Django-tenant-schemas is not compatible with newer versions of Django, so I had to switch to more up-to-date fork called Django-tenants. Hope this answer will help someone updating their codebase to latest Django versions.

Upvotes: 3

Related Questions