migrate and upgrade error
migrate and upgrade path: models_path=migrations\models\old_models in tortoise.init 355 line import_module(models_path) error raise ConfigurationError(f'Module "{models_path}" not found')
change tortoise.init 355 line:
if '\' in models_path:
models_path = '.'.join(models_path.split('\'))
# models_path = migrations.models.old_models
抱歉英文不好, 迁移和更新时生成的路径migrations\models\old_models在tortoise.init 355 line中import_module(models_path)时由于识别路径的关系引发的错误, 修改源码可以解决
是执行哪一步的时候出错了?
是执行哪一步的时候出错了?
就是执行迁移的时候出错了, 迁移的时候产生的路径是migrations\models\old_models这样的, 乌龟没有识别, 他要识别migrations.models.old_models这样的, 上面我提到的修改乌龟的init文件355行可以解决目前的问题,我的乌龟版本是tortoise 0.1.1,
是aerich的版本吧?你升级最新的0.2.0试试
是aerich的版本吧?你升级最新的0.2.0试试
好的, 我目前的是0.1.9, 由于替换了源装不上0.2.0, 我把源改回去试试
从最新的dev分支安装
I cannot upgrade with either aerich 0.2.0 nor the latest dev branch. With 0.2.0 the error is
ModuleNotFoundError: No module named 'migrations\\models\\old_models'
On the latest dev, the error is
ModuleNotFoundError: No module named '/migrations'
Can you please help/advise?
I'm using windows 10, python 3.8.
@mosheduminer Can I see your aerich.ini?
@long2ice my aerich.ini file is as follows:
[aerich]
tortoise_orm = app.settings.TORTOISE_ORM
location = ./migrations
Sorry I can't point you towards a repo, the code is private.
Since you use windows,your location maybe .\migrations
@long2ice that fixed it! Thanks! Only now I have another issue, my models are defined in multiple files, with relative imports between them. Would it be correct to say that aerich cannot handle relative imports?
You can give a try.
Ah, I was asking because I get the following error:
ModuleNotFoundError: No module named 'migrations.models.user'
Which appears to happen due to a relative import...
It seems that all the models are put in a single old_models file, without the imports being removed. For example, this is taken from the __init__.py file:
from .user import User
from .building import Building
from .apartment import Apartment
from .package import Package
with further imports between files. I changed the imports to be absolute, and everything works now. Thanks you so much for your help!
You are welcome.
@long2ice Hello, regarding Module "\migrations\models\old_models" not found, I used your method above and still failed to solve my problem. Is there any other way to deal with it? The following is the directory structure of my test project https://note.youdao.com/yws/api/personal/file/WEB10281d2a965db99ebbef67a0fe7874d2?method=download&shareKey=3ffe95da605e5e5ae8b22f2a1986a163