tags:

views:

241

answers:

1

Here is my current code:

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

I then try to execute:

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

And receive the error:

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.

In my development.ini I have:

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

I'm new to Python's pylons and have no idea how to resolve this message. This is probably an easy fix to the trained eye. Thank you.

+1  A: 

This issue was resolved. I didn't know that when using pylons from the CLI, I have to include the entire environment:

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 *

After this the database queries executed without a problem.

ensnare