From 480a857fe8828381cd48727bd9a644113491ddf8 Mon Sep 17 00:00:00 2001 From: M1ha Date: Mon, 21 Jan 2019 12:35:44 +0500 Subject: [PATCH] Fix error on migration, if MigrationHistory database is readonly and has not been created yet --- src/django_clickhouse/migrations.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/django_clickhouse/migrations.py b/src/django_clickhouse/migrations.py index 0fec09c..f883b21 100644 --- a/src/django_clickhouse/migrations.py +++ b/src/django_clickhouse/migrations.py @@ -7,12 +7,11 @@ from typing import Optional, Set from django.db import DEFAULT_DB_ALIAS as DJANGO_DEFAULT_DB_ALIAS from django.db.models.signals import post_migrate from django.dispatch import receiver -from infi.clickhouse_orm.database import ServerError - -from django_clickhouse.clickhouse_models import ClickHouseModel +from infi.clickhouse_orm.database import ServerError, DatabaseException from infi.clickhouse_orm.migrations import * from infi.clickhouse_orm.utils import import_submodules +from .clickhouse_models import ClickHouseModel from .configuration import config from .database import connections, Database from .utils import lazy_class_import, module_exists @@ -143,6 +142,12 @@ class MigrationHistory(ClickHouseModel): if ex.code in {81, 60}: return set() raise ex + except DatabaseException as ex: + # If database doesn't exist no migrations are applied + # This prevents readonly=True + db_exists=False infi exception + if str(ex) == 'Database does not exist, and cannot be created under readonly connection': + return set() + raise ex @classmethod def table_name(cls):