Hello all. I'm currently working on a Pylons project, and working on a
model for organizing images on the site. I have yet to even implement
anything relating to its function, since I keep on receiving the
following error pertaining to the model:

InvalidRequestError: One or more mappers failed to compile. Exception
was probably suppressed within a hasattr() call. Message was: Could
not find table 'images' with which to generate a foreign key


Here is the code:

def now():
    return datetime.datetime.now()


imgtag_assoc = schema.Table('imgtag_assoc', schema.MetaData(),
    schema.Column('image_id', types.Integer,
schema.ForeignKey('images.id')),
    schema.Column('tag_id', types.Integer,
schema.ForeignKey('tags.id'))
)

class Tag(Base):
    __tablename__ = 'tags'

    id = schema.Column(types.Integer,
       schema.Sequence('tag_id', optional=True), primary_key=True)
    name = schema.Column(types.Unicode(23), nullable=False,
unique=True)

class Image(Base):
    __tablename__ = 'images'

    id = schema.Column(types.Integer,
        schema.Sequence('image_id', optional=True), primary_key=True)
    # There will be three main types of images. This will provide the
reference to them.
    images = orm.relation("ImageFile",backref="images")
    title = schema.Column(types.Unicode(50), default="(New Image)")
    enabled = schema.Column(types.Integer, default=1)
    # Original uploader of the file.
    owner =
schema.Column(types.Unicode(25),schema.ForeignKey("users.id"))
    # Where and why this file was uploaded
    origin = schema.Column(types.Unicode(50), default="(New Image)")
    # Many-to-many relationship
    tags = orm.relation("Tag",
secondary=imgtag_assoc,backref="images")
    # md5 hash of originally uploaded file
    md5 = schema.Column(types.Text(), nullable=False)
    uploaded = schema.Column(types.TIMESTAMP(), default=now())
    def __init__(self,info,data):
        for k,v in info:
            setattr(self, k, v)
    def getImage(self,type=1):
        pass

class ImageFile(Base):
    __tablename__ = 'image_files'

    id = schema.Column(types.Integer,
        schema.Sequence('imgfile_id', optional=True),
primary_key=True)
    image_id = schema.Column(types.Integer,
        schema.ForeignKey('images.id'), nullable=False)
    # 1 = large; 2 = decent-sized photo; 3 = thumbnail; Will place
dimensions here
    img_type = schema.Column(types.Integer,nullable=False,default=1)
    # /path/to/file
    filename = schema.Column(types.Text(), nullable=False)
    def __init__(self,info):
        for k,v in info:
            setattr(self, k, v)


If I comment out the tags attribute in Image, everything seems to work
perfectly, which is what has lead me to believe that this is the
problem.

Does anyone have any thoughts on what I'm doing wrong? I looked at the
SQLAlchemy website, and this is how they showed to implement a many-to-
many using the declarative base.

By the way, I'm using SQLAlchemy 0.6.4, if that helps at all.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to