citusdata / django-multitenant

Python/Django support for distributed multi-tenant databases like Postgres+Citus
MIT License
747 stars 123 forks source link

AttributeError: tenant_id field not found. Please add tenant_id field to the model ActivityQuerySet #177

Open jugurtha114 opened 1 year ago

jugurtha114 commented 1 year ago

i get this error even though i followed all instructions in doc:

Traceback (most recent call last): File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner self.run() File "/usr/lib/python3.11/threading.py", line 975, in run self._target(*self._args, **self._kwargs) File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/utils/autoreload.py", line 64, in wrapper fn(*args, **kwargs) File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/core/management/commands/runserver.py", line 133, in inner_run self.check(display_num_errors=True) File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/core/management/base.py", line 485, in check all_issues = checks.run_checks( ^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/core/checks/registry.py", line 88, in run_checks new_errors = check(app_configs=app_configs, databases=databases) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/core/checks/urls.py", line 14, in check_url_config return check_resolver(resolver) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/core/checks/urls.py", line 24, in check_resolver return check_method() ^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 494, in check for pattern in self.url_patterns: ^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__ res = instance.__dict__[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 715, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) ^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/utils/functional.py", line 57, in __get__ res = instance.__dict__[self.name] = self.func(instance) ^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/urls/resolvers.py", line 708, in urlconf_module return import_module(self.urlconf_name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1206, in _gcd_import File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/config/urls.py", line 32, in <module> path("api/", include("config.api_router")), ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/urls/conf.py", line 38, in include urlconf_module = import_module(urlconf_module) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/lib/python3.11/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<frozen importlib._bootstrap>", line 1206, in _gcd_import File "<frozen importlib._bootstrap>", line 1178, in _find_and_load File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 690, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 940, in exec_module File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/config/api_router.py", line 4, in <module> from jugu.apps.activities.activities.api.views import ActivityViewSet, ActivityItemViewSet File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/jugu/apps/activities/activities/api/views.py", line 3, in <module> from jugu.apps.activities.activities.api.filters import ActivityItemFilter, ActivityFilter File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/jugu/apps/activities/activities/api/filters.py", line 6, in <module> class ActivityFilter(FilterSet): File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_filters/filterset.py", line 62, in __new__ new_class.base_filters = new_class.get_filters() ^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_filters/filterset.py", line 340, in get_filters filters[filter_name] = cls.filter_for_field( ^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_filters/filterset.py", line 363, in filter_for_field field, lookup_type = resolve_field(field, lookup_expr) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_filters/utils.py", line 204, in resolve_field query = model_field.model._default_manager.all().query ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/jugu/apps/base/helpers/custom_base_manager.py", line 47, in all return self.get_queryset() ^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/jugu/apps/activities/activities/model_manager.py", line 41, in get_queryset return ActivityQuerySet(self.model, using=self._db) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django/db/models/query.py", line 295, in __init__ self.model = model ^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_multitenant/mixins.py", line 140, in __setattr__ attrname in (self.tenant_field, get_tenant_field(self).name) ^^^^^^^^^^^^^^^^^ File "/home/jugu/PycharmProjects/lex_algeria/new_version/law_firm_manager_backend/venv/lib/python3.11/site-packages/django_multitenant/mixins.py", line 216, in tenant_field raise AttributeError( AttributeError: tenant_id field not found. Please add tenant_id field to the model ActivityQuerySet

gurkanindibay commented 1 year ago

@jugurtha114 Could you add the code you used the django-multitenant library with ? THanks