aerich icon indicating copy to clipboard operation
aerich copied to clipboard

FileNotFoundError: ...\\aerich.exe\\__main__.py'

Open chrisdewa opened this issue 5 years ago • 18 comments

When trying to execute aerich init-db i get the following error and traceback:

Success create app migrate location ./migrations\models
Traceback (most recent call last):
  File "c:\users\chris\appdata\local\programs\python\python38\lib\runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\chris\appdata\local\programs\python\python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "C:\Users\chris\AppData\Local\Programs\Python\Python38\Scripts\aerich.exe\__main__.py", line 7, in <module>
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\aerich\cli.py", line 231, in main
    cli(_anyio_backend="asyncio")
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 799, in __call__
    return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\anyio\__init__.py", line 68, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\anyio\_backends\_asyncio.py", line 99, in run
    raise exception
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\anyio\_backends\_asyncio.py", line 67, in wrapper
    retval = await func(*args)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 802, in _main
    return await main(*args, **kwargs)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 748, in main
    rv = await self.invoke(ctx)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 1175, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 994, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\asyncclick\core.py", line 588, in invoke
    rv = await rv
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\aerich\cli.py", line 211, in init_db
    Migrate.write_old_models(config, app, location)
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\aerich\migrate.py", line 198, in write_old_models
    cls.cp_models(app, old_model_files, os.path.join(location, app, cls.get_old_model_file()))
  File "c:\users\chris\appdata\local\programs\python\python38\lib\site-packages\aerich\migrate.py", line 157, in cp_models
    with open(model_file, "r") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\chris\\AppData\\Local\\Programs\\Python\\Python38\\Scripts\\aerich.exe\\__main__.py'

I'm working on a windows 10 computer. Command was called through powershell. Python version is 3.8.2 aerich was installed using regular pip install aerich

chrisdewa avatar Jun 18 '20 20:06 chrisdewa

Sorry, it don't test in windows because I use Mac always, do you exec aerich init first?

long2ice avatar Jun 19 '20 01:06 long2ice

do you exec aerich init first? Yes, first i did: aerich init -t .rute.to.dict and then aerich init-db i do have linux for windows and it sort of worked but i runned into another error. My tortoise init function is inside the same file i have my models. so the config looks like this:

config = {
        'connections': {
            'default': f'sqlite://{DEFAULT_PATH}'
        },
        'apps': {
            'models': {
                'models': ['__main__', 'aerich.models'],
                # If no default_connection specified, defaults to 'default'
                'default_connection': 'default',
            }
        }
    }

it works fine when i run it with tortoise, but it doenst work with aerich. What im i missing?

chrisdewa avatar Jun 19 '20 02:06 chrisdewa

Maybe it because __main__

long2ice avatar Jun 19 '20 02:06 long2ice

probably... should i move all models to another file called modules. then change the dict to:

config = {
        'connections': {
            'default': f'sqlite://{DEFAULT_PATH}'
        },
        'apps': {
            'models': {
                'models': ['modules.models', 'aerich.models'],
                # If no default_connection specified, defaults to 'default'
                'default_connection': 'default',
            }
        }
    }

modules being the folder where i'd save the models.py file with only the models, is that alright?

chrisdewa avatar Jun 19 '20 02:06 chrisdewa

Yes

long2ice avatar Jun 19 '20 02:06 long2ice

So it kind of worked but theres a couple extra errors. First on init-db, the process outputs

Success create app migrate location ./migrations/models
Success generate schema for app "models"
^CException ignored in: <module 'threading' from '/usr/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt:

the process hanged indefinetly so i had to terminate it. Then i did aerich migrate --name "new column" which output:

Success migrate 0_202018061820221822_init.json

^CException ignored in: <module 'threading' from '/usr/lib/python3.8/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 1388, in _shutdown
    lock.acquire()
KeyboardInterrupt:

But again the process hanged there so had to be terminated.

Then i finally did: aerich upgrade but this happened:

returning exception You can only execute one statement at a time.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 171, in run
    result = function()
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 154, in _execute_fetchall
    cursor = self._conn.execute(sql, parameters)
sqlite3.Warning: You can only execute one statement at a time.
Traceback (most recent call last):
  File "/usr/local/bin/aerich", line 10, in <module>
    sys.exit(main())
  File "/usr/local/lib/python3.8/dist-packages/aerich/cli.py", line 231, in main
    cli(_anyio_backend="asyncio")
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 799, in __call__
    return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
  File "/usr/local/lib/python3.8/dist-packages/anyio/__init__.py", line 68, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 99, in run
    raise exception
  File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 67, in wrapper
    retval = await func(*args)
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 802, in _main
    return await main(*args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 748, in main
    rv = await self.invoke(ctx)
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 1175, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 994, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.8/dist-packages/asyncclick/core.py", line 588, in invoke
    rv = await rv
  File "/usr/local/lib/python3.8/dist-packages/aerich/cli.py", line 103, in upgrade
    await conn.execute_query(upgrade_query)
  File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/sqlite/client.py", line 29, in translate_exceptions_
    return await func(self, query, *args)
  File "/usr/local/lib/python3.8/dist-packages/tortoise/backends/sqlite/client.py", line 132, in execute_query
    rows = await connection.execute_fetchall(query, values)
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 255, in execute_fetchall
    return await self._execute(self._execute_fetchall, sql, parameters)
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 185, in _execute
    return await future
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 171, in run
    result = function()
  File "/usr/local/lib/python3.8/dist-packages/aiosqlite/core.py", line 154, in _execute_fetchall
    cursor = self._conn.execute(sql, parameters)
sqlite3.Warning: You can only execute one statement at a time.

and again the procees hanged there indefinetly, so had to be killed.

chrisdewa avatar Jun 19 '20 03:06 chrisdewa

There maybe a bug of aiosqlite, see https://github.com/omnilib/aiosqlite/issues/35 , and also I don't make some tests in sqlite.

long2ice avatar Jun 19 '20 03:06 long2ice

I tried running aerich inside my vps, running ubuntu 20.04, fully updated. But it returned this issue. By the way, the conection still hangs, and needs to be keyboard interrupted.

eturning exception near "DROP": syntax error
Traceback (most recent call last):
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 171, in run
    result = function()
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 154, in _execute_fetchall
    cursor = self._conn.execute(sql, parameters)
sqlite3.OperationalError: near "DROP": syntax error
Traceback (most recent call last):
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/tortoise/backends/sqlite/client.py", line 29, in translate_exceptions_
    return await func(self, query, *args)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/tortoise/backends/sqlite/client.py", line 132, in execute_query
    rows = await connection.execute_fetchall(query, values)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 255, in execute_fetchall
    return await self._execute(self._execute_fetchall, sql, parameters)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 185, in _execute
    return await future
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 171, in run
    result = function()
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aiosqlite/core.py", line 154, in _execute_fetchall
    cursor = self._conn.execute(sql, parameters)
sqlite3.OperationalError: near "DROP": syntax error

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/aura_dragonbot/.local/bin/aerich", line 8, in <module>
    sys.exit(main())
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aerich/cli.py", line 231, in main
    cli(_anyio_backend="asyncio")
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 799, in __call__
    return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/anyio/__init__.py", line 68, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 99, in run
    raise exception
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/anyio/_backends/_asyncio.py", line 67, in wrapper
    retval = await func(*args)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 802, in _main
    return await main(*args, **kwargs)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 748, in main
    rv = await self.invoke(ctx)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 1175, in invoke
    return await _process_result(await sub_ctx.command.invoke(sub_ctx))
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 994, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/asyncclick/core.py", line 588, in invoke
    rv = await rv
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/aerich/cli.py", line 103, in upgrade
    await conn.execute_query(upgrade_query)
  File "/home/aura_dragonbot/.local/lib/python3.8/site-packages/tortoise/backends/sqlite/client.py", line 31, in translate_exceptions_
    raise OperationalError(exc)
tortoise.exceptions.OperationalError: near "DROP": syntax error

chrisdewa avatar Jun 19 '20 20:06 chrisdewa

Can you show json version file in migrations dir?

long2ice avatar Jun 20 '20 03:06 long2ice

Можете ли вы показать файл версии JSON в migrationsDIR?

this is my json for migrations

{
  "upgrade": [
    "CREATE TABLE IF NOT EXISTS \"category\" (\n    \"id\" SERIAL NOT NULL PRIMARY KEY,\n    \"name\" VARCHAR(20) NOT NULL UNIQUE,\n    \"tag\" VARCHAR(20) NOT NULL UNIQUE,\n    \"created_at\" TIMESTAMP NOT NULL  DEFAULT CURRENT_TIMESTAMP,\n    \"edited_at\" TIMESTAMP NOT NULL  DEFAULT CURRENT_TIMESTAMP\n);\nCOMMENT ON TABLE \"category\" IS 'The User model';\nCREATE TABLE IF NOT EXISTS \"question\" (\n    \"id\" SERIAL NOT NULL PRIMARY KEY,\n    \"text\" VARCHAR(255),\n    \"created_at\" DATE NOT NULL,\n    \"edited_at\" DATE NOT NULL,\n    \"category_id\" INT NOT NULL REFERENCES \"category\" (\"id\") ON DELETE CASCADE\n);\nCOMMENT ON TABLE \"question\" IS 'The User model';\nCREATE TABLE IF NOT EXISTS \"aerich\" (\n    \"id\" SERIAL NOT NULL PRIMARY KEY,\n    \"version\" VARCHAR(50) NOT NULL,\n    \"app\" VARCHAR(20) NOT NULL\n);"
  ]
}

And I have the next structure of project

image

@long2ice I suggest adding a replacement here path = path.replace("/", ".").replace('\', '.').lstrip(".")

DmitriyDmytruk avatar Jun 23 '20 18:06 DmitriyDmytruk

Which db do you use? sqlite may not work.

long2ice avatar Jun 24 '20 01:06 long2ice

Какой БД вы используете? sqlite может не работать.

PostgreSQL Windows 10 as OS

m0nte-cr1st0 avatar Jun 24 '20 07:06 m0nte-cr1st0

I fix a bug for windows, you can install from dev branch and try it.

long2ice avatar Jun 24 '20 07:06 long2ice

I fix a bug for windows, you can install from dev branch and try it.

When I try aerich migrate --name drop_column I get error tortoise.exceptions.ConfigurationError: Module "/migrations.models.old_models" not found

Traceback (most recent call last):
  File "D:\pet_projects\fastapi_questions\venv\Scripts\aerich-script.py", line 33, in <module>
    sys.exit(load_entry_point('aerich', 'console_scripts', 'aerich')())
  File "d:\pet_projects\fastapi_questions\venv\src\aerich\aerich\cli.py", line 232, in main
    cli(_anyio_backend="asyncio")
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 799, in __call__
    return anyio.run(self._main, main, args, kwargs, backend=_anyio_backend)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\anyio\__init__.py", line 68, in run
    return asynclib.run(func, *args, **backend_options)  # type: ignore
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 99, in run
    raise exception
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 67, in wrapper
    retval = await func(*args)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 802, in _main
    return await main(*args, **kwargs)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 748, in main
    rv = await self.invoke(ctx)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 1172, in invoke
    await Command.invoke(self, ctx)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 994, in invoke
    return await ctx.invoke(self.callback, **ctx.params)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\asyncclick\core.py", line 588, in invoke
    rv = await rv
  File "d:\pet_projects\fastapi_questions\venv\src\aerich\aerich\cli.py", line 68, in cli
    await Migrate.init_with_old_models(tortoise_config, app, location)
  File "d:\pet_projects\fastapi_questions\venv\src\aerich\aerich\migrate.py", line 60, in init_with_old_models
    await Tortoise.init(config=migrate_config)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\tortoise\__init__.py", line 557, in init
    cls._init_apps(apps_config)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\tortoise\__init__.py", line 426, in _init_apps
    cls.init_models(info["models"], name, _init_relations=False)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\tortoise\__init__.py", line 407, in init_models
    app_models += cls._discover_models(module, app_label)
  File "d:\pet_projects\fastapi_questions\venv\lib\site-packages\tortoise\__init__.py", line 356, in _discover_models
    raise ConfigurationError(f'Module "{models_path}" not found')
tortoise.exceptions.ConfigurationError: Module "/migrations.models.old_models" not found

It's happenes because aerich.ini file has location = ./migrations. For windows here must be location = .\migrations

If I try aerich init -t db.TORTOISE_ORM --location=.\migrations it's work fine. Very thnx. This is a great solution.

DmitriyDmytruk avatar Jun 24 '20 08:06 DmitriyDmytruk

OK, that's difference between in *nix and windows.

long2ice avatar Jun 24 '20 08:06 long2ice

Can you show json version file in migrations dir?

Im sorry for the delay, had troubles in more than one area of life....

{
  "upgrade": [
    "CREATE TABLE IF NOT EXISTS \"configurations\" (\n    \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n    \
"guild_id\" INT NOT NULL,\n    \"leaders_role\" INT,\n    \"make_roles\" INT NOT NULL  DEFAULT 0,\n    \"prefix\" T
EXT NOT NULL,\n    \"urls\" INT   DEFAULT 0,\n    \"invites\" INT   DEFAULT 0\n);\nCREATE TABLE IF NOT EXISTS \"rol
e_bl\" (\n    \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n    \"guild_id\" INT NOT NULL,\n    \"role_id\" I
NT NOT NULL\n);\nCREATE TABLE IF NOT EXISTS \"tribes\" (\n    \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n 
   \"guild_id\" INT NOT NULL,\n    \"name\" TEXT NOT NULL,\n    \"leader_id\" INT NOT NULL,\n    \"members\" TEXT N
OT NULL,\n    \"role\" INT,\n    \"banner\" TEXT,\n    \"color\" INT   DEFAULT 16711680\n);\nCREATE TABLE IF NOT EX
ISTS \"events\" (\n    \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n    \"guild_id\" INT NOT NULL,\n    \"us
er_id\" INT NOT NULL,\n    \"date\" TIMESTAMP NOT NULL  DEFAULT CURRENT_TIMESTAMP,\n    \"name\" TEXT NOT NULL,\n  
  \"description\" TEXT NOT NULL,\n    \"tribe_id\" INT NOT NULL REFERENCES \"tribes\" (\"id\") ON DELETE CASCADE\n)
;\nCREATE TABLE IF NOT EXISTS \"member_bl\" (\n    \"id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,\n    \"guild_
id\" INT NOT NULL,\n    \"user_id\" INT NOT NULL\n);\nCREATE TABLE IF NOT EXISTS \"aerich\" (\n    \"id\" INTEGER P
RIMARY KEY AUTOINCREMENT NOT NULL,\n    \"version\" VARCHAR(50) NOT NULL,\n    \"app\" VARCHAR(20) NOT NULL\n);"
  ]
}

Im guessing this is the info you requested but there is another json file called, added columns:

{
  "upgrade": [
    "ALTER TABLE \"configurations\" DROP COLUMN \"urls\"",
    "ALTER TABLE \"configurations\" DROP COLUMN \"invites\""
  ],
  "downgrade": [
    "ALTER TABLE \"configurations\" ADD \"urls\" INT   DEFAULT 0",
    "ALTER TABLE \"configurations\" ADD \"invites\" INT   DEFAULT 0"
  ]
}

chrisdewa avatar Jun 24 '20 14:06 chrisdewa

i cloned the dev branch and i've been trying to compile it. make tests however throws this error:

Using python3.8 (3.8.3) Installing dependencies from lock file

No dependencies to install or update

PYTHONDEVMODE=1 TEST_DB=sqlite://:memory: py.test /bin/sh: 1: py.test: not found make: *** [Makefile:36: test] Error 127

chrisdewa avatar Jun 28 '20 18:06 chrisdewa

@chrisdewa I'm here from trying to solve another problem on aiosqlite, butpy.test doesn't exist anymore. You need to call pytest directly.

PythonCoderAS avatar Aug 20 '20 21:08 PythonCoderAS