total novice here. Trying to work with sqlalchemy but have hit a problem.
class Establishment(Base):
__tablename__ = 'establishments'
estaID = Column(String(5), primary_key=True)
typeID = Column(String(2), ForeignKey('types.typeID'))
type = relationship("Type", backref=backref('estabs', order_by=estaID))
def __init__(self, id):
self.estaID = id
try:
session = Session()
existsEsta = session.query(Establishment).filter(Establishment.estaID == self.estaID).one()
session.close()
self.typeID = existsEsta.typeID
except NoResultFound, e:
session = Session()
print "Establishment: ", self.estaID, "does not yet exist."
type = Type(raw_input("Please enter type: "))
self.typeID = type.gettypeID()
print "Adding establishment", self.estaID, self.typeID
session.add(self)
session.commit
For some reason, the session.add(self) is not adding the record to the db. I’m having particular difficult figuring out what’s going on because this “Establishment” class is modeled after another class (identical algorithm, different variable names) which works just fine.
Thoughts as to where I’m going wrong here?
Thanks in advance.
Try
session.commit()instead ofsession.commit.