Google Groups won't let me reply to the existing thread.  Darn wonky
AJAX.

The UniqueConstraint fails inside SQLAlchemy when referencing a
foreign key field.

So something like this:

 30 class Foo(Entity):
 31     belongs_to('bar', of_kind='Bar')
 32     has_field('id', Integer(), primary_key=True)
 33     using_mapper_options(extension=FooME())
 34     using_table_options(UniqueConstraint('bar_id', 'id'))

throws this error:

Traceback (most recent call last):
  File "foo.py", line 30, in ?
    class Foo(Entity):
  File "/home/victorng/dev/elixir/elixir/entity.py", line 317, in
__init__
    desc.setup()
  File "/home/victorng/dev/elixir/elixir/entity.py", line 110, in
setup
    self.setup_table()
  File "/home/victorng/dev/elixir/elixir/entity.py", line 220, in
setup_table
    self.entity.table = Table(self.tablename, self.metadata,
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 173, in
__call__
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 36, in
_init_items
  File "build/bdist.linux-i686/egg/sqlalchemy/schema.py", line 971, in
_set_parent
  File "build/bdist.linux-i686/egg/sqlalchemy/util.py", line 134, in
__getitem__
  File "build/bdist.linux-i686/egg/sqlalchemy/util.py", line 229, in
__getitem__
KeyError: 'bar_id'

The workaround is to just push out the UniqueConstraint outside of the
class definition and do:

Foo._descriptor.add_constraint(UniqueConstraint(...))

vic


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to