I have default schema for my API, and existing schema for data search. This is db settings:
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"OPTIONS": {"options": "-c search_path=public"},
"NAME": config("DB_NAME", default=""),
"USER": config("DB_USER_NAME", default=""),
"PASSWORD": config("DB_PASSWORD", default=""),
"HOST": config("DB_HOST", default="db"),
"PORT": config("DB_PORT", default=""),
},
"data": {
"ENGINE": "django.db.backends.postgresql",
"OPTIONS": {"options": "-c search_path=data"},
"NAME": config("DB_NAME", default=""),
"USER": config("DB_USER_NAME", default=""),
"PASSWORD": config("DB_PASSWORD", default=""),
"HOST": config("DB_HOST", default="db"),
"PORT": config("DB_PORT", default=""),
},
}
For "data" I used the comand python manage.py inspectdb --database=data > apps/data/models.py
And got models.py like this:
class Product(models.Model):
id = models.AutoField(primary_key=True)
...
class Meta:
managed = False
db_table = "Product"
I've tried create some pytest:
@pytest.mark.django_db(databases=["default", "data"], transaction=True)
class TestSomeTestAPIView:
view_name = "some-view-name"
def test_some_test_name(self, auth_client):
print(Product.objects.using("data").all())
And got the error
"Product" table does not exists
So I need use existing db schema "data" without creating migrations, and use default schema as usual.
I've tried https://pytest-django.readthedocs.io/en/latest/database.html but it does not work in my case. Any ideas how to run pytests?