diff --git a/aerich/cli.py b/aerich/cli.py index 6880acb..a1bb164 100644 --- a/aerich/cli.py +++ b/aerich/cli.py @@ -240,8 +240,7 @@ async def init( with open(config_file, "w", encoding="utf-8") as f: parser.write(f) - if not Path(location).is_dir(): - os.mkdir(location) + Path(location).mkdir(parents=True, exist_ok=True) click.secho(f"Success create migrate location {location}", fg=Color.green) click.secho(f"Success generate config file {config_file}", fg=Color.green) @@ -263,10 +262,10 @@ async def init_db(ctx: Context, safe): app = ctx.obj["app"] dirname = Path(location, app) - if not dirname.is_dir(): - os.mkdir(dirname) + try: + dirname.mkdir(parents=True) click.secho(f"Success create app migrate location {dirname}", fg=Color.green) - else: + except FileExistsError: return click.secho( f"Inited {app} already, or delete {dirname} and try again.", fg=Color.yellow )