Click to See Complete Forum and Search --> : Raw MySQL with SQLAlchemy using Pyramid (python) framework


Awais-Muzaffar
02-19-2011, 04:50 AM
Hello guys,

I have recently made a decision to start using the Pyramid (python web framework) for my projects from now on.

I have also decided to use SQLalchemy, and I want to use raw MySQL (personal reasons) but still keep the ORM features.

The first part of the code in models.py reads:

DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension()))
Base = declarative_base()

Now from here how do I exectue a query for CREATE TABLE using raw MySQL.

the traditional SQLalchemy way would be:

class Page(Base):
__tablename__ = 'pages'
id = Column(Integer, primary_key=True)
name = Column(Text, unique=True)
data = Column(Text)

def __init__(self, name, data):
self.name = name
self.data = data

I have tried the following:

DBSession.execute( """ CREATE TABLE ..... """ )

and recieve the following error: UnboundExecutionError: Could not locate a bind configured on SQL expression or this Session