bernardopires / django-tenant-schemas

Tenant support for Django using PostgreSQL schemas.
https://django-tenant-schemas.readthedocs.org/en/latest/
MIT License
1.46k stars 424 forks source link

migrate_schemas not running #648

Open maxwellcc opened 4 years ago

maxwellcc commented 4 years ago

Using in requirements.txt

Django==3.1 django-tenant-schemas==1.10.0

In settings.py

image

image

philippbosch commented 4 years ago

I'm having the same issue with Django 3.1 and DTS 1.10.0.

maxwellcc commented 4 years ago

I discovered the reason for the problem. This error occurs in versions of Django greater than 3.0.9. So, I downgraded from version 3.1 to version 3.0.9

danh91 commented 4 years ago

Hi guys, I am having the same problem too using Django 3.1 and DTS 1.10.0.

I looked around and realized that it has something to do with the changes in Django related to the skip_checks command option.

That said, here are different solutions/workarounds I found

1 - Add requires_system_checks = [] to migrate_schemas command class

class Command(SyncCommon):
    requires_system_checks = []
    ...

2 - Or customize BaseCommand.create_parser(prog_name, subcommand, **kwargs) to tell arg parser not to raise an exception when an argument is defined twice. (https://docs.python.org/3/library/argparse.html#conflict-handler)

class Command(SyncCommon):
   ...

    def create_parser(self, prog_name, subcommand, **kwargs):
        return super().create_parser(prog_name, subcommand, **{**kwargs, 'conflict_handler': 'resolve'})

    ...

I am more inclined to go with solution 1, I will make a PR with that. Please let me know what you think or if there is an even better way to approach it, I wouldn't say I have a complete picture this is the first time I am using DTS.

In the meantime, you can locally override the migrate_schemas command to add the fix locally following https://docs.djangoproject.com/en/3.0/howto/custom-management-commands/

from tenant_schemas.management.commands.migrate_schemas import Command as MigrateSchemasCommand

class Command(MigrateSchemasCommand):
    requires_system_checks = []
sshahbaj commented 4 years ago

Are all these issues related? #641 #634 #613

sshahbaj commented 4 years ago

@goodtune

MaickDavila commented 4 years ago

Aun existe este problema, entonce la solucion es bajar la version de Django, o existe otra solución?

4k45hv3rm4 commented 3 years ago

Hi guys, I am having the same problem too using Django 3.1 and DTS 1.10.0.

I looked around and realized that it has something to do with the changes in Django related to the skip_checks command option.

That said, here are different solutions/workarounds I found

1 - Add requires_system_checks = [] to migrate_schemas command class

class Command(SyncCommon):
    requires_system_checks = []
    ...

2 - Or customize BaseCommand.create_parser(prog_name, subcommand, **kwargs) to tell arg parser not to raise an exception when an argument is defined twice. (https://docs.python.org/3/library/argparse.html#conflict-handler)

class Command(SyncCommon):
   ...

    def create_parser(self, prog_name, subcommand, **kwargs):
        return super().create_parser(prog_name, subcommand, **{**kwargs, 'conflict_handler': 'resolve'})

    ...

I am more inclined to go with solution 1, I will make a PR with that. Please let me know what you think or if there is an even better way to approach it, I wouldn't say I have a complete picture this is the first time I am using DTS.

In the meantime, you can locally override the migrate_schemas command to add the fix locally following https://docs.djangoproject.com/en/3.0/howto/custom-management-commands/

from tenant_schemas.management.commands.migrate_schemas import Command as MigrateSchemasCommand

class Command(MigrateSchemasCommand):
    requires_system_checks = []

Thanks first solution worked for me