sqlAlchemy映射器未定义

时间:2016-04-16 03:34:41

标签: python sqlalchemy

我收到以下错误消息:

Traceback (most recent call last):
File "alchemyTest.py", line 12, in <module>
planetMapper = mapper(Planet, planet)
NameError: name 'mapper' is not defined

我的SQLAlchemy版本是1.0.12。我使用以下代码:

connection = db.connect();
metadata = MetaData(db);

class Planet(object):
    pass

planet = Table('PLANET', metadata, autoload=True)
planetMapper = mapper(Planet, planet)

我在线搜索过,无法在mapper上找到任何未定义的内容。任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

from sqlalchemy.orm import mapper