<p dir="auto"><strong>Migrated issue, originally created by Krzysztof Malinowski (<a href="https://github.com/boromil">@boromil</a>)</strong></p>
<p dir="auto">Using the official docker form IBM for DB2 10.5.5:</p>
<p dir="auto"><a href="https://hub.docker.com/r/ibmcom/db2express-c/" rel="nofollow">https://hub.docker.com/r/ibmcom/db2express-c/</a></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="docker run -it -p 50000:50000 -e DB2INST1_PASSWORD=mypass -e LICENSE=accept ibmcom/db2express-c:latest bash

# create db
su - db2inst1
db2start
db2sampl
"><pre class="notranslate"><code class="notranslate">docker run -it -p 50000:50000 -e DB2INST1_PASSWORD=mypass -e LICENSE=accept ibmcom/db2express-c:latest bash

# create db
su - db2inst1
db2start
db2sampl

</code></pre></div>
<p dir="auto">python requirements:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!
sqlalchemy==1.0.17
ibm-db==2.0.5.1
ibm_db_sa==0.3.2"><pre class="notranslate"><code class="notranslate">#!
sqlalchemy==1.0.17
ibm-db==2.0.5.1
ibm_db_sa==0.3.2
</code></pre></div>
<p dir="auto">(btw. tried this with the newest versions also - same result)</p>
<p dir="auto">OS:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!
Ubuntu 14.04 64bit"><pre class="notranslate"><code class="notranslate">#!
Ubuntu 14.04 64bit
</code></pre></div>
<p dir="auto">Doing:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine

Base = automap_base()
engine = create_engine(&quot;db2://db2inst1:mypass@172.18.0.1:50000/SAMPLE&quot;)
Base.prepare(engine, reflect=True)
"><pre class="notranslate"><code class="notranslate">from sqlalchemy.ext.automap import automap_base
from sqlalchemy import create_engine

Base = automap_base()
engine = create_engine("db2://db2inst1:mypass@172.18.0.1:50000/SAMPLE")
Base.prepare(engine, reflect=True)

</code></pre></div>
<p dir="auto">raises:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;db2_automap.py&quot;, line 8, in &lt;module&gt;
    Base.prepare(engine, reflect=True)
  File &quot;/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py&quot;, line 777, in prepare
    generate_relationship)
  File &quot;/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py&quot;, line 899, in _relationships_for_fks
    nullable = False not in set([fk.parent.nullable for fk in fks])
AttributeError: 'NoneType' object has no attribute 'nullable'"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "db2_automap.py", line 8, in &lt;module&gt;
    Base.prepare(engine, reflect=True)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py", line 777, in prepare
    generate_relationship)
  File "/usr/local/lib/python2.7/dist-packages/sqlalchemy/ext/automap.py", line 899, in _relationships_for_fks
    nullable = False not in set([fk.parent.nullable for fk in fks])
AttributeError: 'NoneType' object has no attribute 'nullable'
</code></pre></div>
<p dir="auto">seems that some fk-s have incorrect <em>parent</em> and <em>column</em> attributes</p>
<p dir="auto"><strong>Migrated issue, originally created by Jorge Sierra</strong></p>
<p dir="auto">conn_str = string.Template('db2+ibm_db://$user:$password@localhost:50000/Sample').substitute(user = user , password = password)</p>
<p dir="auto">for t in metadata.sorted_tables:<br>
logger.info ("CreateTable %s %s" % (t.name, <strong>CreateTable</strong>(t).compile(db2)))</p>
<p dir="auto">When trying to run <strong>CreateTable</strong></p>
<p dir="auto"><strong>compiler.py</strong></p>
<p dir="auto">around line 2588<br>
under function</p>
<p dir="auto">def <strong>visit_foreign_key_constraint</strong>(self, constraint):</p>
<p dir="auto">this function is assuming <strong>f.parent</strong> is never  'None' and in my case it was, same as  <strong>f.column</strong></p>
<p dir="auto">This is the fix below</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="list_text1 = [] 
for f in constraint.elements:
 if f.parent is not None:
   list_text1.append(preparer.quote(f.parent.name))
   
list_text2 = [] 
for f in constraint.elements:
 if hasattr(f, 'column'):
   if f.column is not None:
     list_text2.append(preparer.quote(f.column.name))           
     
text += &quot;FOREIGN KEY(%s) REFERENCES %s (%s)&quot; % (
      ', '.join(list_text1),
      self.define_constraint_remote_table(
          constraint, remote_table, preparer),
      ', '.join(list_text2))
text += self.define_constraint_match(constraint)
text += self.define_constraint_cascades(constraint)
text += self.define_constraint_deferrability(constraint)
return text
"><pre class="notranslate"><code class="notranslate">list_text1 = [] 
for f in constraint.elements:
 if f.parent is not None:
   list_text1.append(preparer.quote(f.parent.name))
   
list_text2 = [] 
for f in constraint.elements:
 if hasattr(f, 'column'):
   if f.column is not None:
     list_text2.append(preparer.quote(f.column.name))           
     
text += "FOREIGN KEY(%s) REFERENCES %s (%s)" % (
      ', '.join(list_text1),
      self.define_constraint_remote_table(
          constraint, remote_table, preparer),
      ', '.join(list_text2))
text += self.define_constraint_match(constraint)
text += self.define_constraint_cascades(constraint)
text += self.define_constraint_deferrability(constraint)
return text

</code></pre></div>