On Tue, 29 Jul 2014, Simon King wrote:
Hope that helps,
Simon, and others:
As a check that I understand the basics please check the syntax of this
set of three related tables:
class Agencies(Base):
__tablename__ = 'agencies'
org_name = Column(String(48), primary_key = True)
acronym = Column(String(8), value=' ', nullable = False)
org_lvl = Column(String(8), value='State', nullable = False,
CheckConstraint(org_lvl("org_lvl IN ('Federal', 'State', 'County',
'City', 'Local', 'Regional')")
website = Column(String(64), value=' ')
comment = Column(STring)
class Agency_Units(Base):
__tablename__ = 'agency_units'
unit_name = Column(String(48), nullable = False, unique = True, primary_key
= True)
parent_name = Column(String(48), nullable = False,
ForeignKey('agencies.org_name'), primary_key = True)
agencies = relationship("Agencies", backref=backref('agency_units'))
acronym = Column(String(8))
addr1 = Column(String(32), nullable = False)
addr2 = Column(String(32))
city = Column(String(16), nullable = False)
state_prov = Column(String(2), nullable = False)
postcode = Column(String(10), nullable = False)
phone = Column(String(10))
fax = Column(String(10))
website = Column(String(64))
comment = Column(String)
class Agency_Contacts(Base):
__tablename__ = 'agency_contacts'
last_name = Column(String(20), nullable = False, primary_key = True)
first_name = Column(String(16), nullable = False, primary_key = True)
mi = Column(String(1))
agency_unit = Column(String(48), nullable = False, primary_key = True,
ForeignKey('agency_units.unit_name'))
agency_unites = relationship("Agency_Units",
backref=backref('agency_contacts'))
title = Column(String(32))
phone = Column(String(10), nullable = False)
extension = Column(String(6))
email = Column(String(32))
start_date = Column(Date, nullable = False)
end_date = Column(Date)
comments = Column(String)
I think that's how to express multiple column primary keys and the foreign
references; at least, that's how I interpreted the doc. Getting corrected
now will make life easier in the future.
Thanks in advance,
Rich
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.