I'm trying to incapsulate some functionality (some columns mainly) into
base classes to inherit my models from them. The setup looks like this:
class EntityTemplate():
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
id = Column(Integer(), primary_key=True)
timestamp = Column(DateTime())
class DocumentTemplate(EntityTemplate):
date = Column(Date())
number = Column(String(5))
Entity = declarative_base(cls=EntityTemplate, name='Entity')Document =
declarative_base(cls=DocumentTemplate, name='Document')
I'm trying to use it like this:
class Customer(Entity):
name = Column(String(25))
address = Column(String(50))
class Invoice(Document):
customer_id = Column(Integer, ForeignKey('customer.id'))
customer = relationship("Customer")
total = Column(Numeric(10,2))
Entity.metadata.create_all(engine)Document.metadata.create_all(engine)
But on the last line I get this:
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with
column'invoice.customer_id' could not find table 'customer' with which to
generate
a foreign key to target column 'id'
If I inherit Invoice from Entity instead of Document, everything is fine
(except the fact that columns date and number are missing). Why? (I'm using
SQLAlchemy-0.7.9-py3.2). Thanks!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/sqlalchemy/-/2IsSRLhqqqAJ.
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.