I replied your email message but also posting my reply here for anyone
else who might run into this.
Short Version
==========
The engine creation step is likely missing from the tutorial.
Longer Version
===========
For the purpose of this discussion say your project is called myapp
In a fresh pylons install with SQLAlchemy selected, the engine is
created when you run
pylons setup-app development.ini
setup-app is defined in myapp/myapp/websetup.py thus :-
def setup_app(command, conf, vars):
"""Place any commands to setup myapp here"""
# Don't reload the app if it was loaded under the testing
environment
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
Base.metadata.create_all(bind=Session.bind)
This in turn calls load_environment() which is defined in
myapp/myapp/config/environment.py
In this file an engine is created and init_model is then called using
the engine. i.e.
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
That is the missing step.
On Jun 5, 3:14 pm, afrotypa <[email protected]> wrote:
> My guess is Session.bind has not been initialized?
>
> Perhaps you need to call init_model which id defined in model/
> __init__.py first? See its definition here :-
>
> def init_model(engine):
> """Call me before using any of the tables or classes in the
> model"""
> Session.configure(bind=engine)
>
> On Jun 5, 11:58 am, Victor <[email protected]> wrote:
>
> > I'm following the PylonsHQ Documentation on
> > models:http://pylonshq.com/docs/en/1.0/models/
>
> > I have managed to follow the docs until the portion where I am trying
> > to create the database. The code I add to websetup.py is as follows:
>
> > from myapp.model.meta import Base, Session
> > log.info("Creating tables")
> > Base.metadata.drop_all(checkfirst=True, bind=Session.bind)
> > Base.metadata.create_all(bind=Session.bind)
> > log.info("Successfully setup")
>
> > When I run "$ paster setup-app development.ini" command, I get the
> > following error:
>
> > 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.
>
> > I am using a MySQL server running on an Ubuntu machine to try out the
> > example.
>
> > Does anybody know why I am getting the error?
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.