anusha kadambala
unread,Feb 9, 2010, 10:57:24 PM2/9/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to sqlal...@googlegroups.com
hello all,
I am newbie in sqlalchemy.I am thrilled by the sqlachemy features. But i got struck in the how to write the not null for the following:
create table organisation(orgcode varchar(30) not null,orgname text not null,primary key(orgcode));
I have written the using declarative base as follows but dont know how to impose not null constraint
from sqlalchemy import create_engine
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker,scoped_session
engine = create_engine('postgresql:///gkanusha', echo=False)
Base = declarative_base()
class Organisation(Base):
__tablename__ = 'Organisation'
orgcode = Column(String,primary_key=True)
orgname = Column(String)
def __init__(self,orgcode,orgname):
self.orgcode = orgcode
self.orgname = orgname
organisation_table = Organisation.__table__
metadata = Base.metadata
metadata.create_all(engine)
Session = scoped_session(sessionmaker(bind=engine))
Session.commit()
There are other columns also but i have taken two columns for simplicity.
Thanks in advance
--
Njoy the share of Freedom :)
Anusha Kadambala