Hey,
how may i extend the declerative base to provide default things that are
always available to any class/table that is derived from it (like primary
keys, create timestamp columns ect) ?
i tried something like this:
import datetime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
Base = declarative_base()
class NewBase(Base):
__tablename__ = "default"
id = Column(Integer, primary_key=True)
created = Column(DateTime, nullable=False,
default=datetime.datetime.now)
class NewCustomTable(NewBase):
__tablename__ = "NewCustomTable"
awesome = Column(String)
but i'm getting either sqlalchemy.exc.NoForeignKeysError or
sqlalchemy.exc.InvalidRequestError depending on declaring the __tablename__
attribute or not.
with __tablename__ :
sqlalchemy.exc.NoForeignKeysError: Can't find any foreign key relationships
between 'default' and 'NewCustomTable'.
without:
sqlalchemy.exc.InvalidRequestError: Class <class 'NewBase'> does not have a
__table__ or __tablename__ specified and does not inherit from an existing
table-mapped class.
Any recommendation about this?
--
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/groups/opt_out.