Skip to content

Create custom types #1168

Description

@MyGodIsHe

Hi All!

I have several databases in my project and one of them is external. I know, it's bad practice but that's how it is. And I need tests for it and pytest-django creates tables from models perfectly, but problems arise with custom types in postgres. I need to insert the creation of types in the interval between the creation of the database and the creation of tables. I found this solution and I don't like it. Is there another way?

@pytest.fixture(scope="session", autouse=True)
def _create_custom_types():
    from django.db.backends.base.schema import BaseDatabaseSchemaEditor

    def create_model(self, model):
        if model == User:
            self.execute("CREATE EXTENSION hstore;")
        orig_create_model(self, model)

    orig_create_model = BaseDatabaseSchemaEditor.create_model
    with patch.object(BaseDatabaseSchemaEditor, "create_model", new=create_model):
        yield

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions