I've recently used sqlacodegen
When I try and run against the generated code it get this message that I've been unable to fix:
Could not determine join condition between parent/child tables on relationship Workgrp.usrmst - there are multiple foreign key paths linking the tables. Specify the 'foreign_keys' argument, providing a list of those columns which should be counted as containing a foreign key reference to the parent table.
I'm wondering if someone can shed some light:
Here is the generated code for the relevant tables causing the issue:
class Workgrp(Owner):
__tablename__ = 'workgrp'
workgrp_id = Column(ForeignKey('owner.owner_id'), primary_key=True)
workgrp_prntid = Column(Numeric(scale=0, asdecimal=False))
workgrp_name = Column(String(256))
workgrp_desc = Column(String(4000))
workgrp_owner = Column(ForeignKey('usrmst.usrmst_id'))
workgrp_lstchgtm = Column(DateTime, index=True)
workgrp_externid = Column(String(20))
workgrp_profile = Column(Text)
workgrp_usrmodtm = Column(DateTime)
usrmst = relationship('Usrmst')
class Usrmst(Owner):
__tablename__ = 'usrmst'
__table_args__ = (
Index('usrmst_ak1', 'usrmst_domain', 'usrmst_name'),
)
usrmst_id = Column(ForeignKey('owner.owner_id'), primary_key=True)
usrmst_domain = Column(String(256))
usrmst_name = Column(String(256), nullable=False)
usrmst_fullname = Column(String(1024))
usrmst_desc = Column(String(4000))
usrmst_phoneno = Column(String(40))
usrmst_pagerno = Column(String(40))
usrmst_email = Column(String(1024))
usrmst_emailtype = Column(Numeric(scale=0, asdecimal=False))
secmst_id = Column(ForeignKey('secmst.secmst_id'))
lngmst_id = Column(ForeignKey('lngmst.lngmst_id'))
usrmst_password = Column(String(1024))
usrmst_externid = Column(String(20))
usrmst_suser = Column(String(1))
usrmst_lstchgtm = Column(DateTime, index=True)
usrmst_orapassword = Column(String(144))
usrmst_wingroup = Column(String(1))
usrmst_tmpacct = Column(String(1))
usrmst_profile = Column(Text)
usrmst_usrmodtm = Column(DateTime)
usrmst_principal = Column(String(256))
usrmst_keytab = Column(String(4000))
lngmst = relationship('Lngmst')
secmst = relationship('Secmst')
I've looked at the SQLAlchemy docs, and tried things with
But ended up with messages like:
- 'Table' object has no attribute 'usrmst_id'
- AttributeError: 'Table' object has no attribute 'workgrp_owner'
Here are some screenshots relevant raw Tables in DBeaver, the Eclipse based SQL Explorer type plugin:
I don't think it should make much difference but I'm developing on:
- Windows Server 2012 RC2
- using Oracle 11g
- With Python 3.6.4
- sqlacodegen 1.1.6
There is a snippet I've added after the generated code, with the relevant imports..
engine = create_engine("oracle://<dbuser>:<dbpwd>@<host>:<port>/<db>")
Session = sessionmaker(bind=engine)
session = Session()
firstjm = session.query(Jobmst).first()
print(firstjm)
Other annoying things about the sqlacodegen generated code:
Didn't generate string implementations, of
__repr__
and__str__
, so printing out a table didn't generically list, table name, followed by key, value pair list for columns and their values.Purports to be PEP compliant code, lines often blew the character limit, and so you'd have to go and reformat long comparison strings 'x x' into 'x' ' x' etc ,