G'day,
I've got a database schema that, after the fact, needs a change (doh!).
I'm using SQLAlchemy and sqlite and the odm in the declarative way.
In sqlite I hand-hacked a change to the table that needed changing,
adding a field (which is not a linked field in any way), using
alter table riders add gender string(1)
And I added into my SQLAlchemy description :
class Riders(Base):
__tablename__ = 'riders'
id = Column(Integer, primary_key = True)
name = Column(String(100), nullable = False)
email = Column(String(100))
phone = Column(String(30))
DoB = Column(DateTime)
# the new bit ...
gender = Column(String(1)) # "M" or "F"
created = Column(DateTime, default=func.now())
effortCounter = Column(Integer, default = 0)
coachId = Column(Integer, ForeignKey('coaches.id'))
squadId = Column(Integer, ForeignKey('squads.id'))
# one to many - each rider has only one coach and squad at any one time
squad = relationship(Squads, backref=backref('riders', order_by=id))
coach = relationship(Coaches, backref=backref('riders', order_by=id))
# but we'll have multiple sets of stats
stats = relationship(RiderStats, backref=backref('riderStats',
order_by=RiderStats.date))
def __init__(self, name, email, phone, DoB, gender, coachId,
squadId, effortCounter = 0, created = datetime.datetime.now()):
self.name = name
self.email = email
self.phone = phone
self.DoB = DoB
# the new bit
self.gender = gender
self.created = created # maybe have this as now()?
self.effortCounter = effortCounter # maybe have this always be
0 at creationtime?
self.coachId = coachId
self.squadId = squadId
Is that the right way to do it?
When I ask sqlite about it gender never shows up in the schema from
.dump or .schema, but the values appear in the dumped data.
Have I missed an important step? Is that the right way to update a
schema in an sqlite database when using it with SQLAlchemy or is there a
better way?
Thank you
Carl
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" 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/sqlalchemy?hl=en.