First, I'm not sure if it's a problem of the package itself or something that I'm doing wrong (I guess it's the second option). I followed all the instructions of documentation (here https://django-tenants.readthedocs.io/en/latest/use.html) and even tho I can't figure out what I'm doing wrong.
I have a app 'costumers' which is held my tenant model. This app is on 'SHARED_APPS' right under 'django_tenants'. My app 'university' is on 'TENANT_APPS'. This app contains all the logic and it has my models.py.
I managed to create tenants correctly, BUT, the problem occurs when I try to use any of my Api endpoints. Example:
I created a tenant called university1 and this tenant has it's own schema on my PostgreSQL database. When I do a post request using an api (using this tenant 'university1'), django is trying to use a table which doesn't exist on my schema. I really don't know what I'm doing wrong.
In my models.py (in my app 'university'), do I have to add anything there? For example class Meta: managed = False and db_table=name_of_table_on_database?
This is a sample of it:
from django.db import models
from comum.models import *
from datetime import datetime
from django.utils.translation import gettext_lazy as _
from django.db import connection
class AcademicUniversity(models.Model):
id_unity = models.AutoField(primary_key=True)
id_unity_ies = models.CharField(max_length=100, unique=True, null=True)
unity_name = models.CharField(max_length=100, null=True)
sigla = models.CharField(max_length=100, null=True)
co_localidade = models.ForeignKey(Localidade, on_delete=models.CASCADE, db_column='co_localidade', related_name='localidade_unidade_academica', null=True)
When the request is made and on my APIView the is_valid method is called, it's raising an exception saying that my relation doesn't exist because django is (somehow) changing the relation name.
This is the query:
DEBUG:django.db.backends:(0.071) SELECT "university_academicunity"."id_unity", "university_academicunity"."id_unity_ies",
"university_academicunity"."unity_name",
"university_academicunity"."sigla",
"university_academicunity"."co_localidade_mec"
FROM "university_academicunity"
WHERE "university_academicunity"."id_unity_ies" = '1' LIMIT 21; args=('1',)
I really appreciate any help. Thank you very much