On 19/02/2011 09:44, AwaisMuzaffar wrote:
I have recently made a decision to start using the Pyramid (python web framework) for my projects from now on.
Yay :-)
I have also decided to use SQLalchemy,
Yay :-)
and I want to use raw MySQL (personal reasons)
Don't be an idiot ;-)
The first part of the code in models.py reads: DBSession = scoped_session(sessionmaker(extension=ZopeTransactionExtension())) Base = declarative_base()
I'm personally biased, but maybe have a ready of: http://packages.python.org/mortar_rdb/use.html
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
No, that's just declaring a model. To create the table you'd do: Page.__table__.create(DBSession().bind)
I have tried the following: DBSession.execute( """ CREATE TABLE artwork ( artwork_id int not null primary key auto_increment, artist_id int not null, cat_id int not null, artwork_img_sml varchar(50), artwork_img varchar(50), title varchar(200), description varchar(200), size varchar(10), price decimal(9,2) ); """ )
You wanted DBSession().execute... But really, why on *earth* would you want to manually execute the create? How are you going to get the table to match the models you want to use?
Please keep in mind I am new to Pylons/Pyramid and SQLAlchemy, therefor my lack of understanding how simple things are working at the moment.
Have a good read of: http://www.sqlalchemy.org/docs/orm/tutorial.html cheers, Chris -- Simplistix - Content Management, Batch Processing & Python Consulting - http://www.simplistix.co.uk -- You received this message because you are subscribed to the Google Groups "pylons-devel" group. To post to this group, send email to pylons-devel@googlegroups.com. To unsubscribe from this group, send email to pylons-devel+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-devel?hl=en.