hi avdd, On Tue, Feb 16, 2010 at 7:01 PM, avdd <adr...@gmail.com> wrote:
> Hi anusha, > > The error is unrelated to your Login query because sqlalchemy compiles > the mappers as late as possible. It might help if you put somewhere > in your application code, after you have imported all your entities, > the lines: > > from sqlalchemy import orm > orm.compile_mappers() > > to catch these sorts of errors early. > Thank you for clarify this error. > > Now the specific problem you see is that the ORM uses the declared > ForeignKeys to determine how to join tables for a relation, but on > your Detail table you have two foreign keys back to account and the > ORM doesn't know which one to use. > But i want to foreign keys as per my requirement. So what i need to do to solve this issue? Is it possible to do it with ORM or not? > > On Feb 16, 9:49 pm, anusha kadambala <anusha.kadamb...@gmail.com> > wrote: > > hello all, > > > > My tables are giving following error at the time of querying. The tables > got > > created properly but when i query on some table it is showing error on > other > > tables.I didnt understand whats the issue here. I am querying on login > table > > it is giving error on debitnote details tables. > > > > Tables: > > ************************** > > class Login(Base): > > __tablename__ = 'login' > > usercode = Column(Integer,primary_key=True) > > username = Column(Text) > > userpassword = Column(Text) > > userrole = Column(Text) > > > > def __init__(self,username,userpassword,userrole): > > self.username = username > > self.userpassword = userpassword > > self.userrole = userrole > > > > login_table = Login.__table__ > > > > class Account(Base): > > __tablename__ = "account" > > accountcode = Column(Integer, primary_key = True) > > groupcode = Column(Integer, ForeignKey("groups.groupcode"), nullable > = > > False) > > groups = relation(Groups, backref = backref("Account", order_by = > > accountcode)) > > accountname = Column(Text, nullable = False) > > basedon = Column(Text) > > accountdesc = Column(Text) > > openingbalance = Column(Numeric(13,2)) > > openingdate = Column(TIMESTAMP) > > initialbalance = Column(Numeric(13,2)) > > > > def > > > __init__(self,groupcode,groups,accountname,basedon,accountdesc,openingbalance,openingdate,initialbalance): > > self.groupcode = groupcode > > self.groups = groups > > self.accountname = accountname > > self.basedon = basedon > > self.accountdesc = accountdesc > > self.openingbalance = openingbalance > > self.openingdate = openingdate > > self.initialbalance = initialbalance > > > > account_table = Account.__table__ > > > > class DebitnoteMaster(Base): > > __tablename__ = "debitnotemaster" > > vouchercode = Column(String(40), primary_key = True) > > sbillno = Column(String(40)) > > voucherdate = Column(TIMESTAMP, nullable = False) > > reffdate = Column(TIMESTAMP) > > booktype = Column(Text) > > chequeno = Column(Text) > > bankname = Column(Text) > > debitnarration = Column(Text, nullable = False) > > > > def > > > __init__(self,vouchercode,sbillno,voucherdate,reffdate,booktype,chequeno,bankname,debitnarration): > > self.vouchercode = vouchercode > > self.sbillno = sbillno > > self.voucherdate = voucherdate > > self.reffdate = reffdate > > self.booktype = booktype > > self.chequeno = chequeno > > self.bankname = bankname > > self.debitnarration = debitnarration > > > > debitnotemaster_table = DebitnoteMaster.__table__ > > > > class DebitnoteDetails(Base): > > __tablename__ = "debitnotedetails" > > dndtcode = Column(Integer, primary_key = True) > > vouchercode = Column(String(40), > > ForeignKey("debitnotemaster.vouchercode")) > > debitnotemaster = relation(DebitnoteMaster, backref = > > backref("DebitnoteDetails", order_by = dndtcode)) > > craccountcode = Column(Integer, ForeignKey("account.accountcode"), > > nullable = False) > > account = relation(Account, backref = backref("DebitnoteDetails", > > order_by = dndtcode)) > > draccountcode = Column(Integer, ForeignKey("account.accountcode"), > > nullable = False) > > account = relation(Account, backref = backref("DebitnoteDetails", > > order_by = dndtcode)) > > amount = Column(Numeric(13,2), nullable = False) > > > > def __init__(self,vouchercode,craccountcode,draccountcode,amount): > > self.vouchercode = vouchercode > > self.craccountcode = craccountcode > > self.draccountcode = draccountcode > > self.amount = amount > > > > debitnotedetails_table = DebitnoteDetails.__table__ > > > > **************************** > > > > Error: > > ***************************** > > > > Traceback (most recent call last): > > File "/usr/lib/python2.6/dist-packages/twisted/web/server.py", line > 150, > > in process > > self.render(resrc) > > File "/usr/lib/python2.6/dist-packages/twisted/web/server.py", line > 157, > > in render > > body = resrc.render(self) > > File "/usr/lib/python2.6/dist-packages/twisted/web/resource.py", line > 190, > > in render > > return m(request) > > File "/usr/lib/python2.6/dist-packages/twisted/web/xmlrpc.py", line > 118, > > in render_POST > > defer.maybeDeferred(function, *args).addErrback( > > --- <exception caught here> --- > > File "/usr/lib/python2.6/dist-packages/twisted/internet/defer.py", line > > 106, in maybeDeferred > > result = f(*args, **kw) > > File > > > "/home/sonal/Desktop/gnukhata_alpha/gnukhata-server/GNUKhata-ApplicationServer/rpc_user.py", > > line 53, in xmlrpc_getUser > > res = Session.query(dbconnect.Login).filter(dbconnect.Login.username > == > > queryParams[0]).filter(dbconnect.Login.userpassword == > > queryParams[1]).first() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/scoping.py", > > line 127, in do > > return getattr(self.registry(), name)(*args, **kwargs) > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/session.py", > > line 875, in query > > return self._query_cls(entities, self, **kwargs) > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/query.py", > > line 91, in __init__ > > self._set_entities(entities) > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/query.py", > > line 100, in _set_entities > > self._setup_aliasizers(self._entities) > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/query.py", > > line 114, in _setup_aliasizers > > mapper, selectable, is_aliased_class = _entity_info(entity) > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/util.py", > > line 512, in _entity_info > > mapper = mapper.compile() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/mapper.py", > > line 696, in compile > > mapper._post_configure_properties() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/mapper.py", > > line 725, in _post_configure_properties > > prop.init() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/interfaces.py", > > line 484, in init > > self.do_init() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/properties.py", > > line 735, in do_init > > self._determine_joins() > > File > > > "/usr/local/lib/python2.6/dist-packages/SQLAlchemy-0.6beta1-py2.6.egg/sqlalchemy/orm/properties.py", > > line 826, in _determine_joins > > "many-to-many relation, 'secondaryjoin' is needed as well." % (self)) > > sqlalchemy.exc.ArgumentError: Could not determine join condition between > > parent/child tables on relation DebitnoteDetails.account. Specify a > > 'primaryjoin' expression. If this is a many-to-many relation, > > 'secondaryjoin' is needed as well. > > > > -- > > > > Thanks in advance > > > > Njoy the share of Freedom :) > > Anusha Kadambala > > -- > 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<sqlalchemy%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/sqlalchemy?hl=en. > > -- Njoy the share of Freedom :) Anusha Kadambala -- 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.