Hi
I'm relatively new to SQLAlchemy, so thanks in advance for any help
with this issue.
I'm trying to construct a class to model a legacy table which has a
composite primary key which is also
a composite foreign key referencing the composite primary key of a
second table. I'm trying to define this
class declaratively, and also have it autoload the remaining table
structure from the underlying table.
This is what I have:
class Wcs(skymapper_db.db.TableBase):
from sqlalchemy import Column, Integer, ForeignKeyConstraint
__tablename__ = 'wcs'
__table_args__ = (
ForeignKeyConstraint(['image_id', 'amp'],
['science_amp.image_id', 'science_amp.amp']),
{'autoload':True}
)
image_id = Column(Integer, primary_key=True)
amp = Column(Integer, primary_key=True)
def __init__(self):
pass
def __repr__(self):
return "<Wcs(%s, %s)>" % (self.image_id, self.amp)
As it stands, I get an error when I try to instantiate this class:
C:\Users\jgs900\Work\skymapper-alchemy>wcs.py
Traceback (most recent call last):
File "C:\Users\jgs900\Work\skymapper-alchemy\wcs.py", line 13, in
<module>
class Wcs(skymapper_db.db.TableBase):
File "C:\Python27\lib\site-packages\sqlalchemy\ext\declarative.py",
line 1017, in __init__
_as_declarative(cls, classname, cls.__dict__)
File "C:\Python27\lib\site-packages\sqlalchemy\ext\declarative.py",
line 926, in _as_declarative
**table_kw)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 209,
in __new__
table._init(name, metadata, *args, **kw)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 269,
in _init
self._init_items(*args)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 60,
in _init_items
item._set_parent(self)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 809,
in _set_parent
table.constraints.remove(fk.constraint)
KeyError: ForeignKeyConstraint()
but if I leave out the autoload instruction, there is no problem.
Am i doing something fundamentally wrong? Or am I just making a syntax
error of some sort. Any help
would be greatly appreciated.
--
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.