From 40c0008e6e4b5180161b50d912d83c349f7aee08 Mon Sep 17 00:00:00 2001 From: long2ice Date: Mon, 25 May 2020 18:02:56 +0800 Subject: [PATCH] Fix upgrade error when migrate --- CHANGELOG.rst | 4 ++++ aerich/__init__.py | 2 +- aerich/cli.py | 9 +++++++-- pyproject.toml | 2 +- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7295845..2e4748c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,10 @@ ChangeLog 0.1 === +0.1.8 +_____ +- Fix upgrade error when migrate. + 0.1.7 ----- - Exclude models.Aerich. diff --git a/aerich/__init__.py b/aerich/__init__.py index f1380ee..9cb17e7 100644 --- a/aerich/__init__.py +++ b/aerich/__init__.py @@ -1 +1 @@ -__version__ = "0.1.7" +__version__ = "0.1.8" diff --git a/aerich/cli.py b/aerich/cli.py index ae2bf86..551da98 100644 --- a/aerich/cli.py +++ b/aerich/cli.py @@ -7,6 +7,7 @@ from enum import Enum import asyncclick as click from asyncclick import Context, UsageError from tortoise import Tortoise, generate_schema_for_client +from tortoise.exceptions import OperationalError from tortoise.transactions import in_transaction from tortoise.utils import get_schema_sql @@ -86,7 +87,11 @@ async def upgrade(ctx: Context): app = ctx.obj["app"] migrated = False for version in Migrate.get_all_version_files(): - if not await Aerich.exists(version=version, app=app): + try: + exists = await Aerich.exists(version=version, app=app) + except OperationalError: + exists = False + if not exists: async with in_transaction(get_app_connection_name(config, app)) as conn: file_path = os.path.join(Migrate.migrate_location, version) with open(file_path, "r") as f: @@ -159,7 +164,7 @@ def history(ctx): ) @click.pass_context async def init( - ctx: Context, tortoise_orm, location, + ctx: Context, tortoise_orm, location, ): config_file = ctx.obj["config_file"] name = ctx.obj["name"] diff --git a/pyproject.toml b/pyproject.toml index b6e2fd0..ec12ae9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "aerich" -version = "0.1.7" +version = "0.1.8" description = "A database migrations tool for Tortoise ORM." authors = ["long2ice "]