2010-02-04 59 views
0

我的SQL表时,这里是我当前的代码:我继续收到“元数据未绑定到引擎或连接”。试图建立与挂架

def init_model(engine): 

    global t_user 
    t_user = sa.Table("User", meta.metadata, 
    sa.Column("id", sa.types.Integer, primary_key=True), 
    sa.Column("name", sa.types.String(100), nullable=False), 
    sa.Column("first_name", sa.types.String(100), nullable=False), 
    sa.Column("last_name", sa.types.String(100), nullable=False),     
    sa.Column("email", sa.types.String(100), nullable=False),      
    sa.Column("password", sa.types.String, nullable=False),      
    autoload=True,                
    autoload_with=engine               
    )                    

    orm.mapper(User, t_user)              

    meta.Session.configure(bind=engine)           
    meta.Session = orm.scoped_session(sm) 
    meta.engine = engine 

然后我试图执行:

>>> meta.metadata.create_all(bind=meta.engine) 

和接收错误:

raise exc.UnboundExecutionError(msg) 
sqlalchemy.exc.UnboundExecutionError: The MetaData is not bound to an Engine or  Connection. Execution can not proceed without a database to execute against. Either execute with an explicit connection or assign the MetaData's .bind to enable implicit execution. 

在我的发展.ini我有:

# SQLAlchemy database URL 
sqlalchemy.url = sqlite:///%(here)s/development.db 

我是Python的挂架新手,不知道如何解决此消息。这对于训练有素的眼睛来说可能是一个简单的解决方案谢谢。

回答

2

此问题已解决。我不知道使用从CLI塔的时候,我必须包括整个环境:

from paste.deploy import appconfig 
from pylons import config 

from project.config.environment import load_environment 

conf = appconfig('config:development.ini', relative_to='.') 
load_environment(conf.global_conf, conf.local_conf) 

from project.model import * 

这个没有问题,执行数据库查询后。

相关问题