[alembic] import the own model into myproject/alembic/env.py

677 views
Skip to first unread message

c.b...@posteo.jp

unread,
Aug 16, 2015, 8:57:58 AM8/16/15
to sqlalchemy
I want to use `alembic revision --autogenerate` with my own model
classes. Because of that I need to import them in
`myproject/alembic/env.py` as [described in the docs][1]. But this
doesn't work even if I tried a lot of variations.

I am not sure in which context (don't know if this is the correct word)
does alembic run the `env.py`. Maybe that causes some errors.

This is the directory and file structure I use.

myproject/
common/
__init__.py
model.py
alembic/
env.py

The error is kind of that

from .common import model
SystemError: Parent module '' not loaded, cannot perform relative
import

`myproject` itself is just a repository/working directory. It is not
*installed* into the system (with `pip3`, `apt-get`, `easyinstall` or
anything else).


[1]: http://alembic.readthedocs.org/en/latest/autogenerate.html

--
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1

mQENBFQIluABCACfPwAhRAwFD3NXgv5CtVUGSiqdfJGVViVBqaKd+14E0pASA0MU
G0Ewj7O7cGy/ZIoiZ0+lIEZmzJKHfuGwYhXjR/PhnUDrQIHLBvh9WuD6JQuULXfH
kXtVm/i9wm76QAcvr2pwYgNzhcJntUHl2GcgnInYbZDeVmg+p9yIPJjuq73/lRS3
0/McgNoFOBhKK/S6STQuFyjr9OyJyYd1shoM3hmy+kg0HYm6OgQBJNg92WV9jwGe
GzlipvEp2jpLwVsTxYir2oOPhfd9D1fC9F/l/3gXbfjd5GIIVrZFq2haZmoVeJ33
LJxo3RA5Tf9LoUeels1b4s9kFz6h7+AHERUpABEBAAG0IUNocmlzdGlhbiBCdWh0
eiA8YnVodHpAcG9zdGVvLmRlPokBPgQTAQIAKAUCVAiW4AIbAwUJAeEzgAYLCQgH
AwIGFQgCCQoLBBYCAwECHgECF4AACgkQZLsXsAdRqOxNUAf/V/hDA5zGDpySuCEj
DhjiVRK74J9Wd8gfH0WAf1Co5HZ24wZH8rgOIVIgXw8rWkOw/VA6xfdfT+64xjTY
Fhkpbrk199nDzp72F7Jc4NC+x8xac2e3rK5ifSWhZx7L5A32pG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/16/15 8:57 AM, c.b...@posteo.jp wrote:
> I want to use `alembic revision --autogenerate` with my own model
> classes. Because of that I need to import them in
> `myproject/alembic/env.py` as [described in the docs][1]. But this
> doesn't work even if I tried a lot of variations.
>
> I am not sure in which context (don't know if this is the correct word)
> does alembic run the `env.py`. Maybe that causes some errors.
>
> This is the directory and file structure I use.
>
> myproject/
> common/
> __init__.py
> model.py
> alembic/
> env.py
>
> The error is kind of that
>
> from .common import model
> SystemError: Parent module '' not loaded, cannot perform relative
> import
>
> `myproject` itself is just a repository/working directory. It is not
> *installed* into the system (with `pip3`, `apt-get`, `easyinstall` or
> anything else).
If you aren't using a virtualenv, then set PYTHONPATH to point to where
"myproject" starts so that you can use a fully-qualified import, e.g.
"import myproject.common.model".





>
>
> [1]: http://alembic.readthedocs.org/en/latest/autogenerate.html
>

Reply all
Reply to author
Forward
0 new messages