<h3 dir="auto">Describe the bug</h3>
<p dir="auto">Using a variant of <code class="notranslate">referred_column</code> in the <code class="notranslate">fk</code> <code class="notranslate">naming_convention</code> placeholder (see <a href="https://docs.sqlalchemy.org/en/14/core/constraints.html#constraint-naming-conventions" rel="nofollow">https://docs.sqlalchemy.org/en/14/core/constraints.html#constraint-naming-conventions</a>), causes an exception, when trying to initialise the ORM.</p>
<p dir="auto">(without using <code class="notranslate">referred_column</code>, this works fine)</p>
<h3 dir="auto">To Reproduce</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import sqlalchemy as sa
from sqlalchemy.orm import declarative_base

Base = declarative_base(
    metadata=MetaData(naming_convention={
        &quot;fk&quot;: &quot;fk_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s_%(referred_column_0_N_name)s&quot;
    }
))

class Model1(Base):
    __tablename__ = 'model1'
    pk = sa.Column('pk', sa.Integer(), primary_key=True)
    model2_pk = sa.Column(sa.Integer(), sa.ForeignKey('model2.pk'))
    
class Model2(Base):
    __tablename__ = 'model2'
    pk = sa.Column('pk', sa.Integer(), primary_key=True)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">sqlalchemy</span> <span class="pl-k">as</span> <span class="pl-s1">sa</span>
<span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">orm</span> <span class="pl-k">import</span> <span class="pl-s1">declarative_base</span>

<span class="pl-v">Base</span> <span class="pl-c1">=</span> <span class="pl-en">declarative_base</span>(
    <span class="pl-s1">metadata</span><span class="pl-c1">=</span><span class="pl-v">MetaData</span>(<span class="pl-s1">naming_convention</span><span class="pl-c1">=</span>{
        <span class="pl-s">"fk"</span>: <span class="pl-s">"fk_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s_%(referred_column_0_N_name)s"</span>
    }
))

<span class="pl-k">class</span> <span class="pl-v">Model1</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model1'</span>
    <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">model2_pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">sa</span>.<span class="pl-v">ForeignKey</span>(<span class="pl-s">'model2.pk'</span>))
    
<span class="pl-k">class</span> <span class="pl-v">Model2</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model2'</span>
    <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)</pre></div>
<p dir="auto">causes</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
NoReferencedTableError                    Traceback (most recent call last)
Input In [100], in &lt;module&gt;
      2 from sqlalchemy.orm import declarative_base
      4 Base = declarative_base(
      5     metadata=MetaData(naming_convention={
      6         &quot;fk&quot;: &quot;fk_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s_%(referred_column_0_N_name)s&quot;
      7     }
      8 ))
---&gt; 10 class Model1(Base):
     11     __tablename__ = 'model1'
     12     pk = sa.Column('pk', sa.Integer(), primary_key=True)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_api.py:72, in DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw)
     69         cls._sa_registry = reg
     71 if not cls.__dict__.get(&quot;__abstract__&quot;, False):
---&gt; 72     _as_declarative(reg, cls, dict_)
     73 type.__init__(cls, classname, bases, dict_)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:126, in _as_declarative(registry, cls, dict_)
    121 def _as_declarative(registry, cls, dict_):
    122 
    123     # declarative scans the class for attributes.  no table or mapper
    124     # args passed separately.
--&gt; 126     return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:177, in _MapperConfig.setup_mapping(cls, registry, cls_, dict_, table, mapper_kw)
    174 else:
    175     cfg_cls = _ClassScanMapperConfig
--&gt; 177 return cfg_cls(registry, cls_, dict_, table, mapper_kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:322, in _ClassScanMapperConfig.__init__(self, registry, cls_, dict_, table, mapper_kw)
    318 self._extract_mappable_attributes()
    320 self._extract_declared_columns()
--&gt; 322 self._setup_table(table)
    324 self._setup_inheritance(mapper_kw)
    326 self._early_mapping(mapper_kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:811, in _ClassScanMapperConfig._setup_table(self, table)
    806         if autoload:
    807             table_kw[&quot;autoload&quot;] = True
    809         table = self.set_cls_attribute(
    810             &quot;__table__&quot;,
--&gt; 811             table_cls(
    812                 tablename,
    813                 self._metadata_for_cls(manager),
    814                 *(tuple(declared_columns) + tuple(args)),
    815                 **table_kw
    816             ),
    817         )
    818 else:
    819     if table is None:

File &lt;string&gt;:2, in __new__(cls, *args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py:309, in deprecated_params.&lt;locals&gt;.decorate.&lt;locals&gt;.warned(fn, *args, **kwargs)
    302     if m in kwargs:
    303         _warn_with_version(
    304             messages[m],
    305             versions[m],
    306             version_warnings[m],
    307             stacklevel=3,
    308         )
--&gt; 309 return fn(*args, **kwargs)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:606, in Table.__new__(cls, *args, **kw)
    604     return table
    605 except Exception:
--&gt; 606     with util.safe_reraise():
    607         metadata._remove_table(name, schema)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py:70, in safe_reraise.__exit__(self, type_, value, traceback)
     68     self._exc_info = None  # remove potential circular references
     69     if not self.warn_only:
---&gt; 70         compat.raise_(
     71             exc_value,
     72             with_traceback=exc_tb,
     73         )
     74 else:
     75     if not compat.py3k and self._exc_info and self._exc_info[1]:
     76         # emulate Py3K's behavior of telling us when an exception
     77         # occurs in an exception handler.

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/compat.py:207, in raise_(***failed resolving arguments***)
    204     exception.__cause__ = replace_context
    206 try:
--&gt; 207     raise exception
    208 finally:
    209     # credit to
    210     # https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/
    211     # as the __traceback__ object creates a cycle
    212     del exception, replace_context, from_, with_traceback

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:602, in Table.__new__(cls, *args, **kw)
    600 metadata._add_table(name, schema, table)
    601 try:
--&gt; 602     table._init(name, metadata, *args, **kw)
    603     table.dispatch.after_parent_attach(table, metadata)
    604     return table

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:688, in Table._init(self, name, metadata, *args, **kwargs)
    677     self._autoload(
    678         metadata,
    679         autoload_with,
   (...)
    682         resolve_fks=resolve_fks,
    683     )
    685 # initialize all the column, etc. objects.  done after reflection to
    686 # allow user-overrides
--&gt; 688 self._init_items(
    689     *args,
    690     allow_replacements=extend_existing or keep_existing or autoload
    691 )

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:135, in SchemaItem._init_items(self, *args, **kw)
    127     util.raise_(
    128         exc.ArgumentError(
    129             &quot;'SchemaItem' object, such as a 'Column' or a &quot;
   (...)
    132         replace_context=err,
    133     )
    134 else:
--&gt; 135     spwd(self, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/base.py:1047, in SchemaEventTarget._set_parent_with_dispatch(self, parent, **kw)
   1045 self.dispatch.before_parent_attach(self, parent)
   1046 self._set_parent(parent, **kw)
-&gt; 1047 self.dispatch.after_parent_attach(self, parent)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/event/attr.py:343, in _CompoundListener.__call__(self, *args, **kw)
    341     fn(*args, **kw)
    342 for fn in self.listeners:
--&gt; 343     fn(*args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:2478, in ForeignKey._set_table(self, column, table)
   2465     self.constraint = ForeignKeyConstraint(
   2466         [],
   2467         [],
   (...)
   2475         **self._unvalidated_dialect_kw
   2476     )
   2477     self.constraint._append_element(column, self)
-&gt; 2478     self.constraint._set_parent_with_dispatch(table)
   2479 table.foreign_keys.add(self)
   2480 # set up remote &quot;.column&quot; attribute, or a note to pick it
   2481 # up when the other Table/Column shows up

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/base.py:1047, in SchemaEventTarget._set_parent_with_dispatch(self, parent, **kw)
   1045 self.dispatch.before_parent_attach(self, parent)
   1046 self._set_parent(parent, **kw)
-&gt; 1047 self.dispatch.after_parent_attach(self, parent)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/event/attr.py:256, in _EmptyListener.__call__(self, *args, **kw)
    253 &quot;&quot;&quot;Execute this event.&quot;&quot;&quot;
    255 for fn in self.parent_listeners:
--&gt; 256     fn(*args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:208, in _constraint_name(const, table)
    205 if isinstance(const.name, conv) or const.name is _NONE_NAME:
    206     return
--&gt; 208 newname = _constraint_name_for_table(const, table)
    209 if newname:
    210     const.name = newname

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:166, in _constraint_name_for_table(const, table)
    155     return const.name
    156 elif (
    157     convention is not None
    158     and not isinstance(const.name, conv)
   (...)
    163     )
    164 ):
    165     return conv(
--&gt; 166         convention
    167         % ConventionDict(const, table, metadata.naming_convention)
    168     )
    169 elif convention is _NONE_NAME:
    170     return None

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:117, in ConventionDict.__getitem__(self, key)
    115 attr = &quot;_key_&quot; + key.replace(&quot;0&quot; + multiples, &quot;X&quot;)
    116 try:
--&gt; 117     tokens.append(getattr(self, attr)(idx))
    118 except AttributeError:
    119     raise KeyError(key)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:95, in ConventionDict._key_referred_column_X_name(self, idx)
     91 fk = self.const.elements[idx]
     92 # note that before [ticket:3989], this method was returning
     93 # the specification for the :class:`.ForeignKey` itself, which normally
     94 # would be using the ``.key`` of the column, not the name.
---&gt; 95 return fk.column.name

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py:1113, in memoized_property.__get__(self, obj, cls)
   1111 if obj is None:
   1112     return self
-&gt; 1113 obj.__dict__[self.__name__] = result = self.fget(obj)
   1114 return result

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:2410, in ForeignKey.column(self)
   2407 parenttable, tablekey, colname = self._resolve_col_tokens()
   2409 if tablekey not in parenttable.metadata:
-&gt; 2410     raise exc.NoReferencedTableError(
   2411         &quot;Foreign key associated with column '%s' could not find &quot;
   2412         &quot;table '%s' with which to generate a &quot;
   2413         &quot;foreign key to target column '%s'&quot;
   2414         % (self.parent, tablekey, colname),
   2415         tablekey,
   2416     )
   2417 elif parenttable.key not in parenttable.metadata:
   2418     raise exc.InvalidRequestError(
   2419         &quot;Table %s is no longer associated with its &quot;
   2420         &quot;parent MetaData&quot; % parenttable
   2421     )

NoReferencedTableError: Foreign key associated with column 'model1.model2_pk' could not find table 'model2' with which to generate a foreign key to target column 'pk'"><pre class="notranslate"><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">NoReferencedTableError</span>                    <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-v">Input</span> <span class="pl-v">In</span> [<span class="pl-c1">100</span>], <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
      <span class="pl-c1">2</span> <span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">orm</span> <span class="pl-k">import</span> <span class="pl-s1">declarative_base</span>
      <span class="pl-c1">4</span> <span class="pl-v">Base</span> <span class="pl-c1">=</span> <span class="pl-en">declarative_base</span>(
      <span class="pl-c1">5</span>     <span class="pl-s1">metadata</span><span class="pl-c1">=</span><span class="pl-v">MetaData</span>(<span class="pl-s1">naming_convention</span><span class="pl-c1">=</span>{
      <span class="pl-c1">6</span>         <span class="pl-s">"fk"</span>: <span class="pl-s">"fk_%(table_name)s_%(column_0_N_name)s_%(referred_table_name)s_%(referred_column_0_N_name)s"</span>
      <span class="pl-c1">7</span>     }
      <span class="pl-c1">8</span> ))
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">10</span> <span class="pl-s1">class</span> <span class="pl-v">Model1</span>(<span class="pl-v">Base</span>):
     <span class="pl-c1">11</span>     <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model1'</span>
     <span class="pl-c1">12</span>     <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_api</span>.<span class="pl-s1">py</span>:<span class="pl-c1">72</span>, <span class="pl-s1">in</span> <span class="pl-v">DeclarativeMeta</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">classname</span>, <span class="pl-s1">bases</span>, <span class="pl-s1">dict_</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
     <span class="pl-c1">69</span>         <span class="pl-s1">cls</span>.<span class="pl-s1">_sa_registry</span> <span class="pl-c1">=</span> <span class="pl-s1">reg</span>
     <span class="pl-c1">71</span> <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">cls</span>.<span class="pl-s1">__dict__</span>.<span class="pl-en">get</span>(<span class="pl-s">"__abstract__"</span>, <span class="pl-c1">False</span>):
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">72</span>     <span class="pl-en">_as_declarative</span>(<span class="pl-s1">reg</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>)
     <span class="pl-c1">73</span> <span class="pl-s1">type</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">classname</span>, <span class="pl-s1">bases</span>, <span class="pl-s1">dict_</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">126</span>, <span class="pl-c1">in</span> <span class="pl-en">_as_declarative</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>)
    <span class="pl-c1">121</span> <span class="pl-s1">def</span> <span class="pl-en">_as_declarative</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>):
    <span class="pl-c1">122</span> 
    <span class="pl-c1">123</span>     <span class="pl-c"># declarative scans the class for attributes.  no table or mapper</span>
    <span class="pl-c1">124</span>     <span class="pl-c"># args passed separately.</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">126</span>     <span class="pl-s1">return</span> <span class="pl-s1">_MapperConfig</span>.<span class="pl-en">setup_mapping</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>, <span class="pl-c1">None</span>, {})

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">177</span>, <span class="pl-c1">in</span> <span class="pl-s1">_MapperConfig</span>.<span class="pl-en">setup_mapping</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">174</span> <span class="pl-k">else</span>:
    <span class="pl-c1">175</span>     <span class="pl-s1">cfg_cls</span> <span class="pl-c1">=</span> <span class="pl-s1">_ClassScanMapperConfig</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">177</span> <span class="pl-s1">return</span> <span class="pl-en">cfg_cls</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">322</span>, <span class="pl-s1">in</span> <span class="pl-s1">_ClassScanMapperConfig</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">318</span> <span class="pl-s1">self</span>.<span class="pl-en">_extract_mappable_attributes</span>()
    <span class="pl-c1">320</span> <span class="pl-s1">self</span>.<span class="pl-en">_extract_declared_columns</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">322</span> <span class="pl-s1">self</span>.<span class="pl-en">_setup_table</span>(<span class="pl-s1">table</span>)
    <span class="pl-c1">324</span> <span class="pl-s1">self</span>.<span class="pl-en">_setup_inheritance</span>(<span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">326</span> <span class="pl-s1">self</span>.<span class="pl-en">_early_mapping</span>(<span class="pl-s1">mapper_kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">811</span>, <span class="pl-s1">in</span> <span class="pl-s1">_ClassScanMapperConfig</span>.<span class="pl-en">_setup_table</span>(<span class="pl-s1">self</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">806</span>         <span class="pl-k">if</span> <span class="pl-s1">autoload</span>:
    <span class="pl-c1">807</span>             <span class="pl-s1">table_kw</span>[<span class="pl-s">"autoload"</span>] <span class="pl-c1">=</span> <span class="pl-c1">True</span>
    <span class="pl-c1">809</span>         <span class="pl-s1">table</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">set_cls_attribute</span>(
    <span class="pl-c1">810</span>             <span class="pl-s">"__table__"</span>,
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">811</span>             <span class="pl-en">table_cls</span>(
    <span class="pl-c1">812</span>                 <span class="pl-s1">tablename</span>,
    <span class="pl-c1">813</span>                 <span class="pl-s1">self</span>.<span class="pl-en">_metadata_for_cls</span>(<span class="pl-s1">manager</span>),
    <span class="pl-c1">814</span>                 <span class="pl-c1">*</span>(<span class="pl-en">tuple</span>(<span class="pl-s1">declared_columns</span>) <span class="pl-c1">+</span> <span class="pl-en">tuple</span>(<span class="pl-s1">args</span>)),
    <span class="pl-c1">815</span>                 <span class="pl-c1">**</span><span class="pl-s1">table_kw</span>
    <span class="pl-c1">816</span>             ),
    <span class="pl-c1">817</span>         )
    <span class="pl-c1">818</span> <span class="pl-k">else</span>:
    <span class="pl-c1">819</span>     <span class="pl-k">if</span> <span class="pl-s1">table</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:

<span class="pl-v">File</span> <span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span>:<span class="pl-c1">2</span>, <span class="pl-c1">in</span> <span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">deprecations</span>.<span class="pl-s1">py</span>:<span class="pl-c1">309</span>, <span class="pl-c1">in</span> <span class="pl-s1">deprecated_params</span>.<span class="pl-c1">&lt;</span><span class="pl-s1">locals</span><span class="pl-c1">&gt;</span>.<span class="pl-s1">decorate</span>.<span class="pl-c1">&lt;</span><span class="pl-s1">locals</span><span class="pl-c1">&gt;</span>.<span class="pl-en">warned</span>(<span class="pl-s1">fn</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">302</span>     <span class="pl-k">if</span> <span class="pl-s1">m</span> <span class="pl-c1">in</span> <span class="pl-s1">kwargs</span>:
    <span class="pl-c1">303</span>         <span class="pl-en">_warn_with_version</span>(
    <span class="pl-c1">304</span>             <span class="pl-s1">messages</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">305</span>             <span class="pl-s1">versions</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">306</span>             <span class="pl-s1">version_warnings</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">307</span>             <span class="pl-s1">stacklevel</span><span class="pl-c1">=</span><span class="pl-c1">3</span>,
    <span class="pl-c1">308</span>         )
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">309</span> <span class="pl-s1">return</span> <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">606</span>, <span class="pl-c1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">604</span>     <span class="pl-k">return</span> <span class="pl-s1">table</span>
    <span class="pl-c1">605</span> <span class="pl-s1">except</span> <span class="pl-v">Exception</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">606</span>     <span class="pl-s1">with</span> <span class="pl-s1">util</span>.<span class="pl-en">safe_reraise</span>():
    <span class="pl-c1">607</span>         <span class="pl-s1">metadata</span>.<span class="pl-en">_remove_table</span>(<span class="pl-s1">name</span>, <span class="pl-s1">schema</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">langhelpers</span>.<span class="pl-s1">py</span>:<span class="pl-c1">70</span>, <span class="pl-c1">in</span> <span class="pl-s1">safe_reraise</span>.<span class="pl-en">__exit__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">type_</span>, <span class="pl-s1">value</span>, <span class="pl-s1">traceback</span>)
     <span class="pl-c1">68</span>     <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>  <span class="pl-c"># remove potential circular references</span>
     <span class="pl-c1">69</span>     <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">self</span>.<span class="pl-s1">warn_only</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">70</span>         <span class="pl-s1">compat</span>.<span class="pl-en">raise_</span>(
     <span class="pl-c1">71</span>             <span class="pl-s1">exc_value</span>,
     <span class="pl-c1">72</span>             <span class="pl-s1">with_traceback</span><span class="pl-c1">=</span><span class="pl-s1">exc_tb</span>,
     <span class="pl-c1">73</span>         )
     <span class="pl-c1">74</span> <span class="pl-k">else</span>:
     <span class="pl-c1">75</span>     <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">compat</span>.<span class="pl-s1">py3k</span> <span class="pl-c1">and</span> <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span> <span class="pl-c1">and</span> <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span>[<span class="pl-c1">1</span>]:
     <span class="pl-c1">76</span>         <span class="pl-c"># emulate Py3K's behavior of telling us when an exception</span>
     <span class="pl-c1">77</span>         <span class="pl-c"># occurs in an exception handler.</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">compat</span>.<span class="pl-s1">py</span>:<span class="pl-c1">207</span>, <span class="pl-c1">in</span> <span class="pl-s1">raise_</span>(<span class="pl-c1">**</span><span class="pl-c1">*</span><span class="pl-s1">failed</span> <span class="pl-s1">resolving</span> <span class="pl-s1">arguments</span><span class="pl-c1">**</span><span class="pl-c1">*</span>)
    <span class="pl-c1">204</span>     <span class="pl-s1">exception</span>.<span class="pl-s1">__cause__</span> <span class="pl-c1">=</span> <span class="pl-s1">replace_context</span>
    <span class="pl-c1">206</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">207</span>     <span class="pl-s1">raise</span> <span class="pl-s1">exception</span>
    <span class="pl-c1">208</span> <span class="pl-s1">finally</span>:
    <span class="pl-c1">209</span>     <span class="pl-c"># credit to</span>
    <span class="pl-c1">210</span>     <span class="pl-c"># https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/</span>
    <span class="pl-c1">211</span>     <span class="pl-c"># as the __traceback__ object creates a cycle</span>
    <span class="pl-c1">212</span>     <span class="pl-k">del</span> <span class="pl-s1">exception</span>, <span class="pl-s1">replace_context</span>, <span class="pl-s1">from_</span>, <span class="pl-s1">with_traceback</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">602</span>, <span class="pl-s1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">600</span> <span class="pl-s1">metadata</span>.<span class="pl-en">_add_table</span>(<span class="pl-s1">name</span>, <span class="pl-s1">schema</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">601</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">602</span>     <span class="pl-s1">table</span>.<span class="pl-en">_init</span>(<span class="pl-s1">name</span>, <span class="pl-s1">metadata</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">603</span>     <span class="pl-s1">table</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">table</span>, <span class="pl-s1">metadata</span>)
    <span class="pl-c1">604</span>     <span class="pl-k">return</span> <span class="pl-s1">table</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">688</span>, <span class="pl-s1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">_init</span>(<span class="pl-s1">self</span>, <span class="pl-s1">name</span>, <span class="pl-s1">metadata</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">677</span>     <span class="pl-s1">self</span>.<span class="pl-en">_autoload</span>(
    <span class="pl-c1">678</span>         <span class="pl-s1">metadata</span>,
    <span class="pl-c1">679</span>         <span class="pl-s1">autoload_with</span>,
   (...)
    <span class="pl-c1">682</span>         <span class="pl-s1">resolve_fks</span><span class="pl-c1">=</span><span class="pl-s1">resolve_fks</span>,
    <span class="pl-c1">683</span>     )
    <span class="pl-c1">685</span> <span class="pl-c"># initialize all the column, etc. objects.  done after reflection to</span>
    <span class="pl-c1">686</span> <span class="pl-c"># allow user-overrides</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">688</span> <span class="pl-s1">self</span>.<span class="pl-en">_init_items</span>(
    <span class="pl-c1">689</span>     <span class="pl-c1">*</span><span class="pl-s1">args</span>,
    <span class="pl-c1">690</span>     <span class="pl-s1">allow_replacements</span><span class="pl-c1">=</span><span class="pl-s1">extend_existing</span> <span class="pl-c1">or</span> <span class="pl-s1">keep_existing</span> <span class="pl-c1">or</span> <span class="pl-s1">autoload</span>
    <span class="pl-c1">691</span> )

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">135</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaItem</span>.<span class="pl-en">_init_items</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">127</span>     <span class="pl-s1">util</span>.<span class="pl-s1">raise_</span>(
    <span class="pl-c1">128</span>         <span class="pl-s1">exc</span>.<span class="pl-v">ArgumentError</span>(
    <span class="pl-c1">129</span>             <span class="pl-s">"'SchemaItem' object, such as a 'Column' or a "</span>
   (...)
    <span class="pl-c1">132</span>         <span class="pl-s1">replace_context</span><span class="pl-c1">=</span><span class="pl-s1">err</span>,
    <span class="pl-c1">133</span>     )
    <span class="pl-c1">134</span> <span class="pl-k">else</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">135</span>     <span class="pl-en">spwd</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1047</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaEventTarget</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
   <span class="pl-c1">1045</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">before_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)
   <span class="pl-c1">1046</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_parent</span>(<span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1047</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">event</span><span class="pl-c1">/</span><span class="pl-s1">attr</span>.<span class="pl-s1">py</span>:<span class="pl-c1">343</span>, <span class="pl-s1">in</span> <span class="pl-s1">_CompoundListener</span>.<span class="pl-en">__call__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">341</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">342</span> <span class="pl-k">for</span> <span class="pl-s1">fn</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">listeners</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">343</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">2478</span>, <span class="pl-s1">in</span> <span class="pl-v">ForeignKey</span>.<span class="pl-en">_set_table</span>(<span class="pl-s1">self</span>, <span class="pl-s1">column</span>, <span class="pl-s1">table</span>)
   <span class="pl-c1">2465</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span> <span class="pl-c1">=</span> <span class="pl-v">ForeignKeyConstraint</span>(
   <span class="pl-c1">2466</span>         [<span class="pl-s1"></span>],
   <span class="pl-c1">2467</span>         [<span class="pl-s1"></span>],
   (...)
   <span class="pl-c1">2475</span>         <span class="pl-c1">**</span><span class="pl-s1">self</span>.<span class="pl-s1">_unvalidated_dialect_kw</span>
   <span class="pl-c1">2476</span>     )
   <span class="pl-c1">2477</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span>.<span class="pl-en">_append_element</span>(<span class="pl-s1">column</span>, <span class="pl-s1">self</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2478</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">table</span>)
   <span class="pl-c1">2479</span> <span class="pl-s1">table</span>.<span class="pl-s1">foreign_keys</span>.<span class="pl-en">add</span>(<span class="pl-s1">self</span>)
   <span class="pl-c1">2480</span> <span class="pl-c"># set up remote ".column" attribute, or a note to pick it</span>
   <span class="pl-c1">2481</span> <span class="pl-c"># up when the other Table/Column shows up</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1047</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaEventTarget</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
   <span class="pl-c1">1045</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">before_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)
   <span class="pl-c1">1046</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_parent</span>(<span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1047</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">event</span><span class="pl-c1">/</span><span class="pl-s1">attr</span>.<span class="pl-s1">py</span>:<span class="pl-c1">256</span>, <span class="pl-s1">in</span> <span class="pl-s1">_EmptyListener</span>.<span class="pl-en">__call__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">253</span> <span class="pl-s">"""Execute this event."""</span>
    <span class="pl-c1">255</span> <span class="pl-k">for</span> <span class="pl-s1">fn</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">parent_listeners</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">256</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">208</span>, <span class="pl-s1">in</span> <span class="pl-en">_constraint_name</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">205</span> <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">const</span>.<span class="pl-s1">name</span>, <span class="pl-s1">conv</span>) <span class="pl-c1">or</span> <span class="pl-s1">const</span>.<span class="pl-s1">name</span> <span class="pl-c1">is</span> <span class="pl-s1">_NONE_NAME</span>:
    <span class="pl-c1">206</span>     <span class="pl-k">return</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">208</span> <span class="pl-s1">newname</span> <span class="pl-c1">=</span> <span class="pl-en">_constraint_name_for_table</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">209</span> <span class="pl-k">if</span> <span class="pl-s1">newname</span>:
    <span class="pl-c1">210</span>     <span class="pl-s1">const</span>.<span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-s1">newname</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">166</span>, <span class="pl-c1">in</span> <span class="pl-en">_constraint_name_for_table</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">155</span>     <span class="pl-k">return</span> <span class="pl-s1">const</span>.<span class="pl-en">name</span>
    <span class="pl-c1">156</span> <span class="pl-k">elif</span> (
    <span class="pl-c1">157</span>     <span class="pl-s1">convention</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>
    <span class="pl-c1">158</span>     <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">const</span>.<span class="pl-s1">name</span>, <span class="pl-s1">conv</span>)
   (...)
    <span class="pl-c1">163</span>     )
    <span class="pl-c1">164</span> ):
    <span class="pl-c1">165</span>     <span class="pl-s1">return</span> <span class="pl-en">conv</span>(
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">166</span>         <span class="pl-s1">convention</span>
    <span class="pl-c1">167</span>         <span class="pl-c1">%</span> <span class="pl-v">ConventionDict</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>, <span class="pl-s1">metadata</span>.<span class="pl-s1">naming_convention</span>)
    <span class="pl-c1">168</span>     )
    <span class="pl-c1">169</span> <span class="pl-k">elif</span> <span class="pl-s1">convention</span> <span class="pl-c1">is</span> <span class="pl-s1">_NONE_NAME</span>:
    <span class="pl-c1">170</span>     <span class="pl-s1">return</span> <span class="pl-c1">None</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">117</span>, <span class="pl-c1">in</span> <span class="pl-v">ConventionDict</span>.<span class="pl-en">__getitem__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>)
    <span class="pl-c1">115</span> <span class="pl-s1">attr</span> <span class="pl-c1">=</span> <span class="pl-s">"_key_"</span> <span class="pl-c1">+</span> <span class="pl-s1">key</span>.<span class="pl-en">replace</span>(<span class="pl-s">"0"</span> <span class="pl-c1">+</span> <span class="pl-s1">multiples</span>, <span class="pl-s">"X"</span>)
    <span class="pl-c1">116</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">117</span>     <span class="pl-s1">tokens</span>.<span class="pl-en">append</span>(<span class="pl-en">getattr</span>(<span class="pl-s1">self</span>, <span class="pl-s1">attr</span>)(<span class="pl-s1">idx</span>))
    <span class="pl-c1">118</span> <span class="pl-s1">except</span> <span class="pl-v">AttributeError</span>:
    <span class="pl-c1">119</span>     <span class="pl-s1">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s1">key</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">95</span>, <span class="pl-c1">in</span> <span class="pl-v">ConventionDict</span>.<span class="pl-en">_key_referred_column_X_name</span>(<span class="pl-s1">self</span>, <span class="pl-s1">idx</span>)
     <span class="pl-c1">91</span> <span class="pl-s1">fk</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">const</span>.<span class="pl-s1">elements</span>[<span class="pl-s1">idx</span>]
     <span class="pl-c1">92</span> <span class="pl-c"># note that before [ticket:3989], this method was returning</span>
     <span class="pl-c1">93</span> <span class="pl-c"># the specification for the :class:`.ForeignKey` itself, which normally</span>
     <span class="pl-c1">94</span> <span class="pl-c"># would be using the ``.key`` of the column, not the name.</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">95</span> <span class="pl-s1">return</span> <span class="pl-s1">fk</span>.<span class="pl-s1">column</span>.<span class="pl-s1">name</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">langhelpers</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1113</span>, <span class="pl-c1">in</span> <span class="pl-s1">memoized_property</span>.<span class="pl-en">__get__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">obj</span>, <span class="pl-s1">cls</span>)
   <span class="pl-c1">1111</span> <span class="pl-k">if</span> <span class="pl-s1">obj</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
   <span class="pl-c1">1112</span>     <span class="pl-s1">return</span> <span class="pl-s1">self</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1113</span> <span class="pl-s1">obj</span>.<span class="pl-s1">__dict__</span>[<span class="pl-s1">self</span>.<span class="pl-s1">__name__</span>] <span class="pl-c1">=</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">fget</span>(<span class="pl-s1">obj</span>)
   <span class="pl-c1">1114</span> <span class="pl-k">return</span> <span class="pl-s1">result</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">2410</span>, <span class="pl-c1">in</span> <span class="pl-v">ForeignKey</span>.<span class="pl-en">column</span>(<span class="pl-s1">self</span>)
   <span class="pl-c1">2407</span> <span class="pl-s1">parenttable</span>, <span class="pl-s1">tablekey</span>, <span class="pl-s1">colname</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">_resolve_col_tokens</span>()
   <span class="pl-c1">2409</span> <span class="pl-k">if</span> <span class="pl-s1">tablekey</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-s1">parenttable</span>.<span class="pl-s1">metadata</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">2410</span>     <span class="pl-k">raise</span> <span class="pl-s1">exc</span>.<span class="pl-v">NoReferencedTableError</span>(
   <span class="pl-c1">2411</span>         <span class="pl-s">"Foreign key associated with column '%s' could not find "</span>
   <span class="pl-c1">2412</span>         <span class="pl-s">"table '%s' with which to generate a "</span>
   <span class="pl-c1">2413</span>         <span class="pl-s">"foreign key to target column '%s'"</span>
   <span class="pl-c1">2414</span>         <span class="pl-c1">%</span> (<span class="pl-s1">self</span>.<span class="pl-s1">parent</span>, <span class="pl-s1">tablekey</span>, <span class="pl-s1">colname</span>),
   <span class="pl-c1">2415</span>         <span class="pl-s1">tablekey</span>,
   <span class="pl-c1">2416</span>     )
   <span class="pl-c1">2417</span> <span class="pl-k">elif</span> <span class="pl-s1">parenttable</span>.<span class="pl-s1">key</span> <span class="pl-c1">not</span> <span class="pl-c1">in</span> <span class="pl-s1">parenttable</span>.<span class="pl-s1">metadata</span>:
   <span class="pl-c1">2418</span>     <span class="pl-k">raise</span> <span class="pl-s1">exc</span>.<span class="pl-v">InvalidRequestError</span>(
   <span class="pl-c1">2419</span>         <span class="pl-s">"Table %s is no longer associated with its "</span>
   <span class="pl-c1">2420</span>         <span class="pl-s">"parent MetaData"</span> <span class="pl-c1">%</span> <span class="pl-s1">parenttable</span>
   <span class="pl-c1">2421</span>     )

<span class="pl-v">NoReferencedTableError</span>: <span class="pl-v">Foreign</span> <span class="pl-s1">key</span> <span class="pl-s1">associated</span> <span class="pl-s1">with</span> <span class="pl-s1">column</span> <span class="pl-s">'model1.model2_pk'</span> <span class="pl-s1">could</span> <span class="pl-c1">not</span> <span class="pl-s1">find</span> <span class="pl-s1">table</span> <span class="pl-s">'model2'</span> <span class="pl-s1">with</span> <span class="pl-s1">which</span> <span class="pl-s1">to</span> <span class="pl-s1">generate</span> <span class="pl-s1">a</span> <span class="pl-s1">foreign</span> <span class="pl-s1">key</span> <span class="pl-s1">to</span> <span class="pl-s1">target</span> <span class="pl-s1">column</span> <span class="pl-s">'pk'</span></pre></div>
<p dir="auto">or, ordering the models the other way:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="class Model2(Base):
    __tablename__ = 'model2'
    pk = sa.Column('pk', sa.Integer(), primary_key=True)

class Model1(Base):
    __tablename__ = 'model1'
    pk = sa.Column('pk', sa.Integer(), primary_key=True)
    model2_pk = sa.Column(sa.Integer(), sa.ForeignKey('model2.pk')"><pre class="notranslate"><span class="pl-k">class</span> <span class="pl-v">Model2</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model2'</span>
    <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-k">class</span> <span class="pl-v">Model1</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model1'</span>
    <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">model2_pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">sa</span>.<span class="pl-v">ForeignKey</span>(<span class="pl-s">'model2.pk'</span>)</pre></div>
<p dir="auto">causes</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="---------------------------------------------------------------------------
NoReferencedColumnError                   Traceback (most recent call last)
Input In [98], in &lt;module&gt;
     10     __tablename__ = 'model2'
     11     pk = sa.Column('pk', sa.Integer(), primary_key=True)
---&gt; 12 class Model1(Base):
     13     __tablename__ = 'model1'
     14     pk = sa.Column('pk', sa.Integer(), primary_key=True)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_api.py:72, in DeclarativeMeta.__init__(cls, classname, bases, dict_, **kw)
     69         cls._sa_registry = reg
     71 if not cls.__dict__.get(&quot;__abstract__&quot;, False):
---&gt; 72     _as_declarative(reg, cls, dict_)
     73 type.__init__(cls, classname, bases, dict_)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:126, in _as_declarative(registry, cls, dict_)
    121 def _as_declarative(registry, cls, dict_):
    122 
    123     # declarative scans the class for attributes.  no table or mapper
    124     # args passed separately.
--&gt; 126     return _MapperConfig.setup_mapping(registry, cls, dict_, None, {})

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:177, in _MapperConfig.setup_mapping(cls, registry, cls_, dict_, table, mapper_kw)
    174 else:
    175     cfg_cls = _ClassScanMapperConfig
--&gt; 177 return cfg_cls(registry, cls_, dict_, table, mapper_kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:322, in _ClassScanMapperConfig.__init__(self, registry, cls_, dict_, table, mapper_kw)
    318 self._extract_mappable_attributes()
    320 self._extract_declared_columns()
--&gt; 322 self._setup_table(table)
    324 self._setup_inheritance(mapper_kw)
    326 self._early_mapping(mapper_kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py:811, in _ClassScanMapperConfig._setup_table(self, table)
    806         if autoload:
    807             table_kw[&quot;autoload&quot;] = True
    809         table = self.set_cls_attribute(
    810             &quot;__table__&quot;,
--&gt; 811             table_cls(
    812                 tablename,
    813                 self._metadata_for_cls(manager),
    814                 *(tuple(declared_columns) + tuple(args)),
    815                 **table_kw
    816             ),
    817         )
    818 else:
    819     if table is None:

File &lt;string&gt;:2, in __new__(cls, *args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py:309, in deprecated_params.&lt;locals&gt;.decorate.&lt;locals&gt;.warned(fn, *args, **kwargs)
    302     if m in kwargs:
    303         _warn_with_version(
    304             messages[m],
    305             versions[m],
    306             version_warnings[m],
    307             stacklevel=3,
    308         )
--&gt; 309 return fn(*args, **kwargs)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:606, in Table.__new__(cls, *args, **kw)
    604     return table
    605 except Exception:
--&gt; 606     with util.safe_reraise():
    607         metadata._remove_table(name, schema)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py:70, in safe_reraise.__exit__(self, type_, value, traceback)
     68     self._exc_info = None  # remove potential circular references
     69     if not self.warn_only:
---&gt; 70         compat.raise_(
     71             exc_value,
     72             with_traceback=exc_tb,
     73         )
     74 else:
     75     if not compat.py3k and self._exc_info and self._exc_info[1]:
     76         # emulate Py3K's behavior of telling us when an exception
     77         # occurs in an exception handler.

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/compat.py:207, in raise_(***failed resolving arguments***)
    204     exception.__cause__ = replace_context
    206 try:
--&gt; 207     raise exception
    208 finally:
    209     # credit to
    210     # https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/
    211     # as the __traceback__ object creates a cycle
    212     del exception, replace_context, from_, with_traceback

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:602, in Table.__new__(cls, *args, **kw)
    600 metadata._add_table(name, schema, table)
    601 try:
--&gt; 602     table._init(name, metadata, *args, **kw)
    603     table.dispatch.after_parent_attach(table, metadata)
    604     return table

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:688, in Table._init(self, name, metadata, *args, **kwargs)
    677     self._autoload(
    678         metadata,
    679         autoload_with,
   (...)
    682         resolve_fks=resolve_fks,
    683     )
    685 # initialize all the column, etc. objects.  done after reflection to
    686 # allow user-overrides
--&gt; 688 self._init_items(
    689     *args,
    690     allow_replacements=extend_existing or keep_existing or autoload
    691 )

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:135, in SchemaItem._init_items(self, *args, **kw)
    127     util.raise_(
    128         exc.ArgumentError(
    129             &quot;'SchemaItem' object, such as a 'Column' or a &quot;
   (...)
    132         replace_context=err,
    133     )
    134 else:
--&gt; 135     spwd(self, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/base.py:1047, in SchemaEventTarget._set_parent_with_dispatch(self, parent, **kw)
   1045 self.dispatch.before_parent_attach(self, parent)
   1046 self._set_parent(parent, **kw)
-&gt; 1047 self.dispatch.after_parent_attach(self, parent)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/event/attr.py:343, in _CompoundListener.__call__(self, *args, **kw)
    341     fn(*args, **kw)
    342 for fn in self.listeners:
--&gt; 343     fn(*args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:2478, in ForeignKey._set_table(self, column, table)
   2465     self.constraint = ForeignKeyConstraint(
   2466         [],
   2467         [],
   (...)
   2475         **self._unvalidated_dialect_kw
   2476     )
   2477     self.constraint._append_element(column, self)
-&gt; 2478     self.constraint._set_parent_with_dispatch(table)
   2479 table.foreign_keys.add(self)
   2480 # set up remote &quot;.column&quot; attribute, or a note to pick it
   2481 # up when the other Table/Column shows up

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/base.py:1047, in SchemaEventTarget._set_parent_with_dispatch(self, parent, **kw)
   1045 self.dispatch.before_parent_attach(self, parent)
   1046 self._set_parent(parent, **kw)
-&gt; 1047 self.dispatch.after_parent_attach(self, parent)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/event/attr.py:256, in _EmptyListener.__call__(self, *args, **kw)
    253 &quot;&quot;&quot;Execute this event.&quot;&quot;&quot;
    255 for fn in self.parent_listeners:
--&gt; 256     fn(*args, **kw)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:208, in _constraint_name(const, table)
    205 if isinstance(const.name, conv) or const.name is _NONE_NAME:
    206     return
--&gt; 208 newname = _constraint_name_for_table(const, table)
    209 if newname:
    210     const.name = newname

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:166, in _constraint_name_for_table(const, table)
    155     return const.name
    156 elif (
    157     convention is not None
    158     and not isinstance(const.name, conv)
   (...)
    163     )
    164 ):
    165     return conv(
--&gt; 166         convention
    167         % ConventionDict(const, table, metadata.naming_convention)
    168     )
    169 elif convention is _NONE_NAME:
    170     return None

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:117, in ConventionDict.__getitem__(self, key)
    115 attr = &quot;_key_&quot; + key.replace(&quot;0&quot; + multiples, &quot;X&quot;)
    116 try:
--&gt; 117     tokens.append(getattr(self, attr)(idx))
    118 except AttributeError:
    119     raise KeyError(key)

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/naming.py:95, in ConventionDict._key_referred_column_X_name(self, idx)
     91 fk = self.const.elements[idx]
     92 # note that before [ticket:3989], this method was returning
     93 # the specification for the :class:`.ForeignKey` itself, which normally
     94 # would be using the ``.key`` of the column, not the name.
---&gt; 95 return fk.column.name

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py:1113, in memoized_property.__get__(self, obj, cls)
   1111 if obj is None:
   1112     return self
-&gt; 1113 obj.__dict__[self.__name__] = result = self.fget(obj)
   1114 return result

File ~/.local/pipx/venvs/jupyterlab/lib/python3.10/site-packages/sqlalchemy/sql/schema.py:2423, in ForeignKey.column(self)
   2418         raise exc.InvalidRequestError(
   2419             &quot;Table %s is no longer associated with its &quot;
   2420             &quot;parent MetaData&quot; % parenttable
   2421         )
   2422     else:
-&gt; 2423         raise exc.NoReferencedColumnError(
   2424             &quot;Could not initialize target column for &quot;
   2425             &quot;ForeignKey '%s' on table '%s': &quot;
   2426             &quot;table '%s' has no column named '%s'&quot;
   2427             % (self._colspec, parenttable.name, tablekey, colname),
   2428             tablekey,
   2429             colname,
   2430         )
   2431 elif hasattr(self._colspec, &quot;__clause_element__&quot;):
   2432     _column = self._colspec.__clause_element__()

NoReferencedColumnError: Could not initialize target column for ForeignKey 'model2.pk' on table 'model1': table 'model2' has no column named 'pk'"><pre class="notranslate"><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span>
<span class="pl-v">NoReferencedColumnError</span>                   <span class="pl-v">Traceback</span> (<span class="pl-s1">most</span> <span class="pl-s1">recent</span> <span class="pl-s1">call</span> <span class="pl-s1">last</span>)
<span class="pl-v">Input</span> <span class="pl-v">In</span> [<span class="pl-c1">98</span>], <span class="pl-s1">in</span> <span class="pl-c1">&lt;</span><span class="pl-s1">module</span><span class="pl-c1">&gt;</span>
     <span class="pl-c1">10</span>     <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model2'</span>
     <span class="pl-c1">11</span>     <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">12</span> <span class="pl-s1">class</span> <span class="pl-v">Model1</span>(<span class="pl-v">Base</span>):
     <span class="pl-c1">13</span>     <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'model1'</span>
     <span class="pl-c1">14</span>     <span class="pl-s1">pk</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s">'pk'</span>, <span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>(), <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_api</span>.<span class="pl-s1">py</span>:<span class="pl-c1">72</span>, <span class="pl-s1">in</span> <span class="pl-v">DeclarativeMeta</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">classname</span>, <span class="pl-s1">bases</span>, <span class="pl-s1">dict_</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
     <span class="pl-c1">69</span>         <span class="pl-s1">cls</span>.<span class="pl-s1">_sa_registry</span> <span class="pl-c1">=</span> <span class="pl-s1">reg</span>
     <span class="pl-c1">71</span> <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">cls</span>.<span class="pl-s1">__dict__</span>.<span class="pl-en">get</span>(<span class="pl-s">"__abstract__"</span>, <span class="pl-c1">False</span>):
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">72</span>     <span class="pl-en">_as_declarative</span>(<span class="pl-s1">reg</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>)
     <span class="pl-c1">73</span> <span class="pl-s1">type</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">classname</span>, <span class="pl-s1">bases</span>, <span class="pl-s1">dict_</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">126</span>, <span class="pl-c1">in</span> <span class="pl-en">_as_declarative</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>)
    <span class="pl-c1">121</span> <span class="pl-s1">def</span> <span class="pl-en">_as_declarative</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>):
    <span class="pl-c1">122</span> 
    <span class="pl-c1">123</span>     <span class="pl-c"># declarative scans the class for attributes.  no table or mapper</span>
    <span class="pl-c1">124</span>     <span class="pl-c"># args passed separately.</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">126</span>     <span class="pl-s1">return</span> <span class="pl-s1">_MapperConfig</span>.<span class="pl-en">setup_mapping</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls</span>, <span class="pl-s1">dict_</span>, <span class="pl-c1">None</span>, {})

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">177</span>, <span class="pl-c1">in</span> <span class="pl-s1">_MapperConfig</span>.<span class="pl-en">setup_mapping</span>(<span class="pl-s1">cls</span>, <span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">174</span> <span class="pl-k">else</span>:
    <span class="pl-c1">175</span>     <span class="pl-s1">cfg_cls</span> <span class="pl-c1">=</span> <span class="pl-s1">_ClassScanMapperConfig</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">177</span> <span class="pl-s1">return</span> <span class="pl-en">cfg_cls</span>(<span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">322</span>, <span class="pl-s1">in</span> <span class="pl-s1">_ClassScanMapperConfig</span>.<span class="pl-en">__init__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">registry</span>, <span class="pl-s1">cls_</span>, <span class="pl-s1">dict_</span>, <span class="pl-s1">table</span>, <span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">318</span> <span class="pl-s1">self</span>.<span class="pl-en">_extract_mappable_attributes</span>()
    <span class="pl-c1">320</span> <span class="pl-s1">self</span>.<span class="pl-en">_extract_declared_columns</span>()
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">322</span> <span class="pl-s1">self</span>.<span class="pl-en">_setup_table</span>(<span class="pl-s1">table</span>)
    <span class="pl-c1">324</span> <span class="pl-s1">self</span>.<span class="pl-en">_setup_inheritance</span>(<span class="pl-s1">mapper_kw</span>)
    <span class="pl-c1">326</span> <span class="pl-s1">self</span>.<span class="pl-en">_early_mapping</span>(<span class="pl-s1">mapper_kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">orm</span><span class="pl-c1">/</span><span class="pl-s1">decl_base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">811</span>, <span class="pl-s1">in</span> <span class="pl-s1">_ClassScanMapperConfig</span>.<span class="pl-en">_setup_table</span>(<span class="pl-s1">self</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">806</span>         <span class="pl-k">if</span> <span class="pl-s1">autoload</span>:
    <span class="pl-c1">807</span>             <span class="pl-s1">table_kw</span>[<span class="pl-s">"autoload"</span>] <span class="pl-c1">=</span> <span class="pl-c1">True</span>
    <span class="pl-c1">809</span>         <span class="pl-s1">table</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">set_cls_attribute</span>(
    <span class="pl-c1">810</span>             <span class="pl-s">"__table__"</span>,
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">811</span>             <span class="pl-en">table_cls</span>(
    <span class="pl-c1">812</span>                 <span class="pl-s1">tablename</span>,
    <span class="pl-c1">813</span>                 <span class="pl-s1">self</span>.<span class="pl-en">_metadata_for_cls</span>(<span class="pl-s1">manager</span>),
    <span class="pl-c1">814</span>                 <span class="pl-c1">*</span>(<span class="pl-en">tuple</span>(<span class="pl-s1">declared_columns</span>) <span class="pl-c1">+</span> <span class="pl-en">tuple</span>(<span class="pl-s1">args</span>)),
    <span class="pl-c1">815</span>                 <span class="pl-c1">**</span><span class="pl-s1">table_kw</span>
    <span class="pl-c1">816</span>             ),
    <span class="pl-c1">817</span>         )
    <span class="pl-c1">818</span> <span class="pl-k">else</span>:
    <span class="pl-c1">819</span>     <span class="pl-k">if</span> <span class="pl-s1">table</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:

<span class="pl-v">File</span> <span class="pl-c1">&lt;</span><span class="pl-s1">string</span><span class="pl-c1">&gt;</span>:<span class="pl-c1">2</span>, <span class="pl-c1">in</span> <span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">deprecations</span>.<span class="pl-s1">py</span>:<span class="pl-c1">309</span>, <span class="pl-c1">in</span> <span class="pl-s1">deprecated_params</span>.<span class="pl-c1">&lt;</span><span class="pl-s1">locals</span><span class="pl-c1">&gt;</span>.<span class="pl-s1">decorate</span>.<span class="pl-c1">&lt;</span><span class="pl-s1">locals</span><span class="pl-c1">&gt;</span>.<span class="pl-en">warned</span>(<span class="pl-s1">fn</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">302</span>     <span class="pl-k">if</span> <span class="pl-s1">m</span> <span class="pl-c1">in</span> <span class="pl-s1">kwargs</span>:
    <span class="pl-c1">303</span>         <span class="pl-en">_warn_with_version</span>(
    <span class="pl-c1">304</span>             <span class="pl-s1">messages</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">305</span>             <span class="pl-s1">versions</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">306</span>             <span class="pl-s1">version_warnings</span>[<span class="pl-s1">m</span>],
    <span class="pl-c1">307</span>             <span class="pl-s1">stacklevel</span><span class="pl-c1">=</span><span class="pl-c1">3</span>,
    <span class="pl-c1">308</span>         )
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">309</span> <span class="pl-s1">return</span> <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">606</span>, <span class="pl-c1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">604</span>     <span class="pl-k">return</span> <span class="pl-s1">table</span>
    <span class="pl-c1">605</span> <span class="pl-s1">except</span> <span class="pl-v">Exception</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">606</span>     <span class="pl-s1">with</span> <span class="pl-s1">util</span>.<span class="pl-en">safe_reraise</span>():
    <span class="pl-c1">607</span>         <span class="pl-s1">metadata</span>.<span class="pl-en">_remove_table</span>(<span class="pl-s1">name</span>, <span class="pl-s1">schema</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">langhelpers</span>.<span class="pl-s1">py</span>:<span class="pl-c1">70</span>, <span class="pl-c1">in</span> <span class="pl-s1">safe_reraise</span>.<span class="pl-en">__exit__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">type_</span>, <span class="pl-s1">value</span>, <span class="pl-s1">traceback</span>)
     <span class="pl-c1">68</span>     <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span> <span class="pl-c1">=</span> <span class="pl-c1">None</span>  <span class="pl-c"># remove potential circular references</span>
     <span class="pl-c1">69</span>     <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">self</span>.<span class="pl-s1">warn_only</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">70</span>         <span class="pl-s1">compat</span>.<span class="pl-en">raise_</span>(
     <span class="pl-c1">71</span>             <span class="pl-s1">exc_value</span>,
     <span class="pl-c1">72</span>             <span class="pl-s1">with_traceback</span><span class="pl-c1">=</span><span class="pl-s1">exc_tb</span>,
     <span class="pl-c1">73</span>         )
     <span class="pl-c1">74</span> <span class="pl-k">else</span>:
     <span class="pl-c1">75</span>     <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">compat</span>.<span class="pl-s1">py3k</span> <span class="pl-c1">and</span> <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span> <span class="pl-c1">and</span> <span class="pl-s1">self</span>.<span class="pl-s1">_exc_info</span>[<span class="pl-c1">1</span>]:
     <span class="pl-c1">76</span>         <span class="pl-c"># emulate Py3K's behavior of telling us when an exception</span>
     <span class="pl-c1">77</span>         <span class="pl-c"># occurs in an exception handler.</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">compat</span>.<span class="pl-s1">py</span>:<span class="pl-c1">207</span>, <span class="pl-c1">in</span> <span class="pl-s1">raise_</span>(<span class="pl-c1">**</span><span class="pl-c1">*</span><span class="pl-s1">failed</span> <span class="pl-s1">resolving</span> <span class="pl-s1">arguments</span><span class="pl-c1">**</span><span class="pl-c1">*</span>)
    <span class="pl-c1">204</span>     <span class="pl-s1">exception</span>.<span class="pl-s1">__cause__</span> <span class="pl-c1">=</span> <span class="pl-s1">replace_context</span>
    <span class="pl-c1">206</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">207</span>     <span class="pl-s1">raise</span> <span class="pl-s1">exception</span>
    <span class="pl-c1">208</span> <span class="pl-s1">finally</span>:
    <span class="pl-c1">209</span>     <span class="pl-c"># credit to</span>
    <span class="pl-c1">210</span>     <span class="pl-c"># https://cosmicpercolator.com/2016/01/13/exception-leaks-in-python-2-and-3/</span>
    <span class="pl-c1">211</span>     <span class="pl-c"># as the __traceback__ object creates a cycle</span>
    <span class="pl-c1">212</span>     <span class="pl-k">del</span> <span class="pl-s1">exception</span>, <span class="pl-s1">replace_context</span>, <span class="pl-s1">from_</span>, <span class="pl-s1">with_traceback</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">602</span>, <span class="pl-s1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">__new__</span>(<span class="pl-s1">cls</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">600</span> <span class="pl-s1">metadata</span>.<span class="pl-en">_add_table</span>(<span class="pl-s1">name</span>, <span class="pl-s1">schema</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">601</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">602</span>     <span class="pl-s1">table</span>.<span class="pl-en">_init</span>(<span class="pl-s1">name</span>, <span class="pl-s1">metadata</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">603</span>     <span class="pl-s1">table</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">table</span>, <span class="pl-s1">metadata</span>)
    <span class="pl-c1">604</span>     <span class="pl-k">return</span> <span class="pl-s1">table</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">688</span>, <span class="pl-s1">in</span> <span class="pl-v">Table</span>.<span class="pl-en">_init</span>(<span class="pl-s1">self</span>, <span class="pl-s1">name</span>, <span class="pl-s1">metadata</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kwargs</span>)
    <span class="pl-c1">677</span>     <span class="pl-s1">self</span>.<span class="pl-en">_autoload</span>(
    <span class="pl-c1">678</span>         <span class="pl-s1">metadata</span>,
    <span class="pl-c1">679</span>         <span class="pl-s1">autoload_with</span>,
   (...)
    <span class="pl-c1">682</span>         <span class="pl-s1">resolve_fks</span><span class="pl-c1">=</span><span class="pl-s1">resolve_fks</span>,
    <span class="pl-c1">683</span>     )
    <span class="pl-c1">685</span> <span class="pl-c"># initialize all the column, etc. objects.  done after reflection to</span>
    <span class="pl-c1">686</span> <span class="pl-c"># allow user-overrides</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">688</span> <span class="pl-s1">self</span>.<span class="pl-en">_init_items</span>(
    <span class="pl-c1">689</span>     <span class="pl-c1">*</span><span class="pl-s1">args</span>,
    <span class="pl-c1">690</span>     <span class="pl-s1">allow_replacements</span><span class="pl-c1">=</span><span class="pl-s1">extend_existing</span> <span class="pl-c1">or</span> <span class="pl-s1">keep_existing</span> <span class="pl-c1">or</span> <span class="pl-s1">autoload</span>
    <span class="pl-c1">691</span> )

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">135</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaItem</span>.<span class="pl-en">_init_items</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">127</span>     <span class="pl-s1">util</span>.<span class="pl-s1">raise_</span>(
    <span class="pl-c1">128</span>         <span class="pl-s1">exc</span>.<span class="pl-v">ArgumentError</span>(
    <span class="pl-c1">129</span>             <span class="pl-s">"'SchemaItem' object, such as a 'Column' or a "</span>
   (...)
    <span class="pl-c1">132</span>         <span class="pl-s1">replace_context</span><span class="pl-c1">=</span><span class="pl-s1">err</span>,
    <span class="pl-c1">133</span>     )
    <span class="pl-c1">134</span> <span class="pl-k">else</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">135</span>     <span class="pl-en">spwd</span>(<span class="pl-s1">self</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1047</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaEventTarget</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
   <span class="pl-c1">1045</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">before_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)
   <span class="pl-c1">1046</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_parent</span>(<span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1047</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">event</span><span class="pl-c1">/</span><span class="pl-s1">attr</span>.<span class="pl-s1">py</span>:<span class="pl-c1">343</span>, <span class="pl-s1">in</span> <span class="pl-s1">_CompoundListener</span>.<span class="pl-en">__call__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">341</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">342</span> <span class="pl-k">for</span> <span class="pl-s1">fn</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">listeners</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">343</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">2478</span>, <span class="pl-s1">in</span> <span class="pl-v">ForeignKey</span>.<span class="pl-en">_set_table</span>(<span class="pl-s1">self</span>, <span class="pl-s1">column</span>, <span class="pl-s1">table</span>)
   <span class="pl-c1">2465</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span> <span class="pl-c1">=</span> <span class="pl-v">ForeignKeyConstraint</span>(
   <span class="pl-c1">2466</span>         [<span class="pl-s1"></span>],
   <span class="pl-c1">2467</span>         [<span class="pl-s1"></span>],
   (...)
   <span class="pl-c1">2475</span>         <span class="pl-c1">**</span><span class="pl-s1">self</span>.<span class="pl-s1">_unvalidated_dialect_kw</span>
   <span class="pl-c1">2476</span>     )
   <span class="pl-c1">2477</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span>.<span class="pl-en">_append_element</span>(<span class="pl-s1">column</span>, <span class="pl-s1">self</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">2478</span>     <span class="pl-s1">self</span>.<span class="pl-s1">constraint</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">table</span>)
   <span class="pl-c1">2479</span> <span class="pl-s1">table</span>.<span class="pl-s1">foreign_keys</span>.<span class="pl-en">add</span>(<span class="pl-s1">self</span>)
   <span class="pl-c1">2480</span> <span class="pl-c"># set up remote ".column" attribute, or a note to pick it</span>
   <span class="pl-c1">2481</span> <span class="pl-c"># up when the other Table/Column shows up</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">base</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1047</span>, <span class="pl-s1">in</span> <span class="pl-v">SchemaEventTarget</span>.<span class="pl-en">_set_parent_with_dispatch</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
   <span class="pl-c1">1045</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">before_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)
   <span class="pl-c1">1046</span> <span class="pl-s1">self</span>.<span class="pl-en">_set_parent</span>(<span class="pl-s1">parent</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1047</span> <span class="pl-s1">self</span>.<span class="pl-s1">dispatch</span>.<span class="pl-en">after_parent_attach</span>(<span class="pl-s1">self</span>, <span class="pl-s1">parent</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">event</span><span class="pl-c1">/</span><span class="pl-s1">attr</span>.<span class="pl-s1">py</span>:<span class="pl-c1">256</span>, <span class="pl-s1">in</span> <span class="pl-s1">_EmptyListener</span>.<span class="pl-en">__call__</span>(<span class="pl-s1">self</span>, <span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)
    <span class="pl-c1">253</span> <span class="pl-s">"""Execute this event."""</span>
    <span class="pl-c1">255</span> <span class="pl-k">for</span> <span class="pl-s1">fn</span> <span class="pl-c1">in</span> <span class="pl-s1">self</span>.<span class="pl-s1">parent_listeners</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">256</span>     <span class="pl-en">fn</span>(<span class="pl-c1">*</span><span class="pl-s1">args</span>, <span class="pl-c1">**</span><span class="pl-s1">kw</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">208</span>, <span class="pl-s1">in</span> <span class="pl-en">_constraint_name</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">205</span> <span class="pl-k">if</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">const</span>.<span class="pl-s1">name</span>, <span class="pl-s1">conv</span>) <span class="pl-c1">or</span> <span class="pl-s1">const</span>.<span class="pl-s1">name</span> <span class="pl-c1">is</span> <span class="pl-s1">_NONE_NAME</span>:
    <span class="pl-c1">206</span>     <span class="pl-k">return</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">208</span> <span class="pl-s1">newname</span> <span class="pl-c1">=</span> <span class="pl-en">_constraint_name_for_table</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">209</span> <span class="pl-k">if</span> <span class="pl-s1">newname</span>:
    <span class="pl-c1">210</span>     <span class="pl-s1">const</span>.<span class="pl-s1">name</span> <span class="pl-c1">=</span> <span class="pl-s1">newname</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">166</span>, <span class="pl-c1">in</span> <span class="pl-en">_constraint_name_for_table</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>)
    <span class="pl-c1">155</span>     <span class="pl-k">return</span> <span class="pl-s1">const</span>.<span class="pl-en">name</span>
    <span class="pl-c1">156</span> <span class="pl-k">elif</span> (
    <span class="pl-c1">157</span>     <span class="pl-s1">convention</span> <span class="pl-c1">is</span> <span class="pl-c1">not</span> <span class="pl-c1">None</span>
    <span class="pl-c1">158</span>     <span class="pl-c1">and</span> <span class="pl-c1">not</span> <span class="pl-en">isinstance</span>(<span class="pl-s1">const</span>.<span class="pl-s1">name</span>, <span class="pl-s1">conv</span>)
   (...)
    <span class="pl-c1">163</span>     )
    <span class="pl-c1">164</span> ):
    <span class="pl-c1">165</span>     <span class="pl-s1">return</span> <span class="pl-en">conv</span>(
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">166</span>         <span class="pl-s1">convention</span>
    <span class="pl-c1">167</span>         <span class="pl-c1">%</span> <span class="pl-v">ConventionDict</span>(<span class="pl-s1">const</span>, <span class="pl-s1">table</span>, <span class="pl-s1">metadata</span>.<span class="pl-s1">naming_convention</span>)
    <span class="pl-c1">168</span>     )
    <span class="pl-c1">169</span> <span class="pl-k">elif</span> <span class="pl-s1">convention</span> <span class="pl-c1">is</span> <span class="pl-s1">_NONE_NAME</span>:
    <span class="pl-c1">170</span>     <span class="pl-s1">return</span> <span class="pl-c1">None</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">117</span>, <span class="pl-c1">in</span> <span class="pl-v">ConventionDict</span>.<span class="pl-en">__getitem__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">key</span>)
    <span class="pl-c1">115</span> <span class="pl-s1">attr</span> <span class="pl-c1">=</span> <span class="pl-s">"_key_"</span> <span class="pl-c1">+</span> <span class="pl-s1">key</span>.<span class="pl-en">replace</span>(<span class="pl-s">"0"</span> <span class="pl-c1">+</span> <span class="pl-s1">multiples</span>, <span class="pl-s">"X"</span>)
    <span class="pl-c1">116</span> <span class="pl-k">try</span>:
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">117</span>     <span class="pl-s1">tokens</span>.<span class="pl-en">append</span>(<span class="pl-en">getattr</span>(<span class="pl-s1">self</span>, <span class="pl-s1">attr</span>)(<span class="pl-s1">idx</span>))
    <span class="pl-c1">118</span> <span class="pl-s1">except</span> <span class="pl-v">AttributeError</span>:
    <span class="pl-c1">119</span>     <span class="pl-s1">raise</span> <span class="pl-v">KeyError</span>(<span class="pl-s1">key</span>)

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">naming</span>.<span class="pl-s1">py</span>:<span class="pl-c1">95</span>, <span class="pl-c1">in</span> <span class="pl-v">ConventionDict</span>.<span class="pl-en">_key_referred_column_X_name</span>(<span class="pl-s1">self</span>, <span class="pl-s1">idx</span>)
     <span class="pl-c1">91</span> <span class="pl-s1">fk</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">const</span>.<span class="pl-s1">elements</span>[<span class="pl-s1">idx</span>]
     <span class="pl-c1">92</span> <span class="pl-c"># note that before [ticket:3989], this method was returning</span>
     <span class="pl-c1">93</span> <span class="pl-c"># the specification for the :class:`.ForeignKey` itself, which normally</span>
     <span class="pl-c1">94</span> <span class="pl-c"># would be using the ``.key`` of the column, not the name.</span>
<span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">95</span> <span class="pl-s1">return</span> <span class="pl-s1">fk</span>.<span class="pl-s1">column</span>.<span class="pl-s1">name</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">util</span><span class="pl-c1">/</span><span class="pl-s1">langhelpers</span>.<span class="pl-s1">py</span>:<span class="pl-c1">1113</span>, <span class="pl-c1">in</span> <span class="pl-s1">memoized_property</span>.<span class="pl-en">__get__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">obj</span>, <span class="pl-s1">cls</span>)
   <span class="pl-c1">1111</span> <span class="pl-k">if</span> <span class="pl-s1">obj</span> <span class="pl-c1">is</span> <span class="pl-c1">None</span>:
   <span class="pl-c1">1112</span>     <span class="pl-s1">return</span> <span class="pl-s1">self</span>
<span class="pl-c1">-</span><span class="pl-c1">&gt;</span> <span class="pl-c1">1113</span> <span class="pl-s1">obj</span>.<span class="pl-s1">__dict__</span>[<span class="pl-s1">self</span>.<span class="pl-s1">__name__</span>] <span class="pl-c1">=</span> <span class="pl-s1">result</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-en">fget</span>(<span class="pl-s1">obj</span>)
   <span class="pl-c1">1114</span> <span class="pl-k">return</span> <span class="pl-s1">result</span>

<span class="pl-v">File</span> <span class="pl-c1">~</span><span class="pl-c1">/</span>.<span class="pl-s1">local</span><span class="pl-c1">/</span><span class="pl-s1">pipx</span><span class="pl-c1">/</span><span class="pl-s1">venvs</span><span class="pl-c1">/</span><span class="pl-s1">jupyterlab</span><span class="pl-c1">/</span><span class="pl-s1">lib</span><span class="pl-c1">/</span><span class="pl-s1">python3</span>.<span class="pl-c1">10</span><span class="pl-c1">/</span><span class="pl-s1">site</span><span class="pl-c1">-</span><span class="pl-s1">packages</span><span class="pl-c1">/</span><span class="pl-s1">sqlalchemy</span><span class="pl-c1">/</span><span class="pl-s1">sql</span><span class="pl-c1">/</span><span class="pl-s1">schema</span>.<span class="pl-s1">py</span>:<span class="pl-c1">2423</span>, <span class="pl-c1">in</span> <span class="pl-v">ForeignKey</span>.<span class="pl-en">column</span>(<span class="pl-s1">self</span>)
   <span class="pl-c1">2418</span>         <span class="pl-k">raise</span> <span class="pl-s1">exc</span>.<span class="pl-v">InvalidRequestError</span>(
   <span class="pl-c1">2419</span>             <span class="pl-s">"Table %s is no longer associated with its "</span>
   <span class="pl-c1">2420</span>             <span class="pl-s">"parent MetaData"</span> <span class="pl-c1">%</span> <span class="pl-s1">parenttable</span>
   <span class="pl-c1">2421</span>         )
   <span class="pl-c1">2422</span>     <span class="pl-k">else</span>:
<span class="pl-c1">-&gt;</span> <span class="pl-c1">2423</span>         <span class="pl-s1">raise</span> <span class="pl-s1">exc</span>.<span class="pl-v">NoReferencedColumnError</span>(
   <span class="pl-c1">2424</span>             <span class="pl-s">"Could not initialize target column for "</span>
   <span class="pl-c1">2425</span>             <span class="pl-s">"ForeignKey '%s' on table '%s': "</span>
   <span class="pl-c1">2426</span>             <span class="pl-s">"table '%s' has no column named '%s'"</span>
   <span class="pl-c1">2427</span>             <span class="pl-c1">%</span> (<span class="pl-s1">self</span>.<span class="pl-s1">_colspec</span>, <span class="pl-s1">parenttable</span>.<span class="pl-s1">name</span>, <span class="pl-s1">tablekey</span>, <span class="pl-s1">colname</span>),
   <span class="pl-c1">2428</span>             <span class="pl-s1">tablekey</span>,
   <span class="pl-c1">2429</span>             <span class="pl-s1">colname</span>,
   <span class="pl-c1">2430</span>         )
   <span class="pl-c1">2431</span> <span class="pl-k">elif</span> <span class="pl-s1">hasattr</span>(<span class="pl-s1">self</span>.<span class="pl-s1">_colspec</span>, <span class="pl-s">"__clause_element__"</span>):
   <span class="pl-c1">2432</span>     <span class="pl-s1">_column</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">_colspec</span>.<span class="pl-s1">__clause_element__</span>()

<span class="pl-v">NoReferencedColumnError</span>: <span class="pl-v">Could</span> <span class="pl-c1">not</span> <span class="pl-s1">initialize</span> <span class="pl-s1">target</span> <span class="pl-s1">column</span> <span class="pl-k">for</span> <span class="pl-v">ForeignKey</span> <span class="pl-s">'model2.pk'</span> <span class="pl-s1">on</span> <span class="pl-s1">table</span> <span class="pl-s">'model1'</span>: <span class="pl-s1">table</span> <span class="pl-s">'model2'</span> <span class="pl-s1">has</span> <span class="pl-s1">no</span> <span class="pl-s1">column</span> <span class="pl-s1">named</span> <span class="pl-s">'pk'</span></pre></div>
<h3 dir="auto">Error</h3>
<p dir="auto">See above</p>
<h3 dir="auto">Versions</h3>
<ul dir="auto">
<li>OS: Mac OS</li>
<li>Python: tested 3.7 and 3.10</li>
<li>SQLAlchemy: 1.4.31</li>
<li>Database: Any</li>
<li>DBAPI (eg: psycopg, cx_oracle, mysqlclient): -</li>
</ul>
<h3 dir="auto">Additional context</h3>
<p dir="auto"><em>No response</em></p>
<p dir="auto">I've read <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="384639205" data-permission-text="Title is private" data-url="https://github.com/sqlalchemy/sqlalchemy/issues/3989" data-hovercard-type="issue" data-hovercard-url="/sqlalchemy/sqlalchemy/issues/3989/hovercard" href="https://github.com/sqlalchemy/sqlalchemy/issues/3989">#3989</a> but this seems unrelated.</p>
<p dir="auto">When defining a <code class="notranslate">ForeignKey</code> on a SQLAlchemy model, if the referenced column is given as a string (<code class="notranslate">{table_name}.{column_name}</code>) and the <code class="notranslate">Base.metadata</code> has been setup with a naming convention that uses any of the<code class="notranslate">referred_column_0[[_]N]_name</code>  tokens for the foreign key convention, then an <code class="notranslate">sqlalchemy.exc.NoReferencedColumnError</code> is raised when the model class is being declared/mapped. Declaring the <code class="notranslate">ForeignKey</code> by passing a <code class="notranslate">Column</code> object works, though.</p>
<p dir="auto">This sample code triggers the bug:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import sqlalchemy as sa
from sqlalchemy import MetaData
from sqlalchemy.ext.declarative import declarative_base


metadata = MetaData(naming_convention={
    &quot;fk&quot;: &quot;fk__%(referred_table_name)s__%(referred_column_0_name)s&quot;,
})
Base = declarative_base(metadata=metadata)

class Parent(Base):
    __tablename__ = 'parent'
    id = sa.Column(sa.Integer, autoincrement=True, primary_key=True)
    parent_id = sa.Column(sa.Integer, sa.ForeignKey('parent.id'))"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">sqlalchemy</span> <span class="pl-k">as</span> <span class="pl-s1">sa</span>
<span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span> <span class="pl-k">import</span> <span class="pl-v">MetaData</span>
<span class="pl-k">from</span> <span class="pl-s1">sqlalchemy</span>.<span class="pl-s1">ext</span>.<span class="pl-s1">declarative</span> <span class="pl-k">import</span> <span class="pl-s1">declarative_base</span>


<span class="pl-s1">metadata</span> <span class="pl-c1">=</span> <span class="pl-v">MetaData</span>(<span class="pl-s1">naming_convention</span><span class="pl-c1">=</span>{
    <span class="pl-s">"fk"</span>: <span class="pl-s">"fk__%(referred_table_name)s__%(referred_column_0_name)s"</span>,
})
<span class="pl-v">Base</span> <span class="pl-c1">=</span> <span class="pl-en">declarative_base</span>(<span class="pl-s1">metadata</span><span class="pl-c1">=</span><span class="pl-s1">metadata</span>)

<span class="pl-k">class</span> <span class="pl-v">Parent</span>(<span class="pl-v">Base</span>):
    <span class="pl-s1">__tablename__</span> <span class="pl-c1">=</span> <span class="pl-s">'parent'</span>
    <span class="pl-s1">id</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>, <span class="pl-s1">autoincrement</span><span class="pl-c1">=</span><span class="pl-c1">True</span>, <span class="pl-s1">primary_key</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
    <span class="pl-s1">parent_id</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>, <span class="pl-s1">sa</span>.<span class="pl-v">ForeignKey</span>(<span class="pl-s">'parent.id'</span>))</pre></div>
<p dir="auto">If I change the last line to</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="    parent_id = sa.Column(sa.Integer, sa.ForeignKey(id))"><pre class="notranslate">    <span class="pl-s1">parent_id</span> <span class="pl-c1">=</span> <span class="pl-s1">sa</span>.<span class="pl-v">Column</span>(<span class="pl-s1">sa</span>.<span class="pl-v">Integer</span>, <span class="pl-s1">sa</span>.<span class="pl-v">ForeignKey</span>(<span class="pl-s1">id</span>))</pre></div>
<p dir="auto">it works as expected. But referencing the column directly is not always possible. Although, in those cases, declaring the <code class="notranslate">ForeignKeyConstraint</code> separately via <code class="notranslate">__table_args__</code> works like a charm.</p>
<p dir="auto"><strong>Error</strong></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;/home/thomas/dev/python/sqlalchemy_test/naming.py&quot;, line 17, in &lt;module&gt;
    class Child(Base):
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/api.py&quot;, line 75, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py&quot;, line 131, in _as_declarative
    _MapperConfig.setup_mapping(cls, classname, dict_)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py&quot;, line 160, in setup_mapping
    cfg_cls(cls_, classname, dict_)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py&quot;, line 190, in __init__
    self._setup_table()
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py&quot;, line 534, in _setup_table
    cls.__table__ = table = table_cls(
  File &quot;&lt;string&gt;&quot;, line 2, in __new__
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py&quot;, line 128, in warned
    return fn(*args, **kwargs)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 507, in __new__
    metadata._remove_table(name, schema)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 68, in __exit__
    compat.raise_(
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/compat.py&quot;, line 178, in raise_
    raise exception
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 502, in __new__
    table._init(name, metadata, *args, **kw)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 601, in _init
    self._init_items(*args)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 118, in _init_items
    spwd(self)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/base.py&quot;, line 460, in _set_parent_with_dispatch
    self.dispatch.after_parent_attach(self, parent)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/event/attr.py&quot;, line 322, in __call__
    fn(*args, **kw)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 2111, in _set_table
    self.constraint._set_parent_with_dispatch(table)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/base.py&quot;, line 460, in _set_parent_with_dispatch
    self.dispatch.after_parent_attach(self, parent)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/event/attr.py&quot;, line 261, in __call__
    fn(*args, **kw)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py&quot;, line 180, in _constraint_name
    newname = _constraint_name_for_table(const, table)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py&quot;, line 157, in _constraint_name_for_table
    convention
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py&quot;, line 108, in __getitem__
    tokens.append(getattr(self, attr)(idx))
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py&quot;, line 86, in _key_referred_column_X_name
    return fk.column.name
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 883, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File &quot;/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py&quot;, line 2057, in column
    raise exc.NoReferencedColumnError(
sqlalchemy.exc.NoReferencedColumnError: Could not initialize target column for ForeignKey 'parent.id' on table 'child': table 'parent' has no column named 'id'"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "/home/thomas/dev/python/sqlalchemy_test/naming.py", line 17, in &lt;module&gt;
    class Child(Base):
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/api.py", line 75, in __init__
    _as_declarative(cls, classname, cls.__dict__)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 131, in _as_declarative
    _MapperConfig.setup_mapping(cls, classname, dict_)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 160, in setup_mapping
    cfg_cls(cls_, classname, dict_)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 190, in __init__
    self._setup_table()
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/ext/declarative/base.py", line 534, in _setup_table
    cls.__table__ = table = table_cls(
  File "&lt;string&gt;", line 2, in __new__
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/deprecations.py", line 128, in warned
    return fn(*args, **kwargs)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 507, in __new__
    metadata._remove_table(name, schema)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 68, in __exit__
    compat.raise_(
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/compat.py", line 178, in raise_
    raise exception
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 502, in __new__
    table._init(name, metadata, *args, **kw)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 601, in _init
    self._init_items(*args)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 118, in _init_items
    spwd(self)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/base.py", line 460, in _set_parent_with_dispatch
    self.dispatch.after_parent_attach(self, parent)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 322, in __call__
    fn(*args, **kw)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 2111, in _set_table
    self.constraint._set_parent_with_dispatch(table)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/base.py", line 460, in _set_parent_with_dispatch
    self.dispatch.after_parent_attach(self, parent)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/event/attr.py", line 261, in __call__
    fn(*args, **kw)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py", line 180, in _constraint_name
    newname = _constraint_name_for_table(const, table)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py", line 157, in _constraint_name_for_table
    convention
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py", line 108, in __getitem__
    tokens.append(getattr(self, attr)(idx))
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/naming.py", line 86, in _key_referred_column_X_name
    return fk.column.name
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/util/langhelpers.py", line 883, in __get__
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/home/thomas/dev/python/sqlalchemy_test/.env/lib/python3.8/site-packages/sqlalchemy/sql/schema.py", line 2057, in column
    raise exc.NoReferencedColumnError(
sqlalchemy.exc.NoReferencedColumnError: Could not initialize target column for ForeignKey 'parent.id' on table 'child': table 'parent' has no column named 'id'
</code></pre></div>
<p dir="auto">After some investigating, I realized the the naming convention was applied before the <code class="notranslate">ForeignKey</code> had been associated to its referenced <code class="notranslate">Column</code> so, as a test, I made this rather crude modification to delay the <code class="notranslate">_set_parent_with_dispatch</code> after the <code class="notranslate">Column</code> had been associated. It works both on 1.3.16 and master, but my knowledge of SQLAlchemy's internals is <strong>not good</strong>, and the fix seems to delay a huge chunk of logic (a lot more than just applying the naming convention). I'm posting it here in case it can help in finding an actual fix.</p>
<div class="highlight highlight-source-diff notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py
index 689eda11d..4245a7f45 100644
--- a/lib/sqlalchemy/sql/schema.py
+++ b/lib/sqlalchemy/sql/schema.py
@@ -2088,6 +2088,7 @@ class ForeignKey(DialectKWArgs, SchemaItem):
         # standalone ForeignKey - create ForeignKeyConstraint
         # on the hosting Table when attached to the Table.
         assert isinstance(table, Table)
+        created = False
         if self.constraint is None:
             self.constraint = ForeignKeyConstraint(
                 [],
@@ -2102,7 +2103,8 @@ class ForeignKey(DialectKWArgs, SchemaItem):
                 **self._unvalidated_dialect_kw
             )
             self.constraint._append_element(column, self)
-            self.constraint._set_parent_with_dispatch(table)
+            created = True
+
         table.foreign_keys.add(self)
         # set up remote &quot;.column&quot; attribute, or a note to pick it
         # up when the other Table/Column shows up
@@ -2124,6 +2126,8 @@ class ForeignKey(DialectKWArgs, SchemaItem):
             _column = self._colspec
             self._set_target_column(_column)
 
+        if created:
+            self.constraint._set_parent_with_dispatch(table)
 
 class DefaultGenerator(SchemaItem):
     &quot;&quot;&quot;Base class for column *default* values.&quot;&quot;&quot;"><pre class="notranslate"><span class="pl-c1">diff --git a/lib/sqlalchemy/sql/schema.py b/lib/sqlalchemy/sql/schema.py</span>
index 689eda11d..4245a7f45 100644
<span class="pl-md">--- a/lib/sqlalchemy/sql/schema.py</span>
<span class="pl-mi1">+++ b/lib/sqlalchemy/sql/schema.py</span>
<span class="pl-mdr">@@ -2088,6 +2088,7 @@</span> class ForeignKey(DialectKWArgs, SchemaItem):
         # standalone ForeignKey - create ForeignKeyConstraint
         # on the hosting Table when attached to the Table.
         assert isinstance(table, Table)
<span class="pl-mi1"><span class="pl-mi1">+</span>        created = False</span>
         if self.constraint is None:
             self.constraint = ForeignKeyConstraint(
                 [],
<span class="pl-mdr">@@ -2102,7 +2103,8 @@</span> class ForeignKey(DialectKWArgs, SchemaItem):
                 **self._unvalidated_dialect_kw
             )
             self.constraint._append_element(column, self)
<span class="pl-md"><span class="pl-md">-</span>            self.constraint._set_parent_with_dispatch(table)</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>            created = True</span>
<span class="pl-mi1"><span class="pl-mi1">+</span></span>
         table.foreign_keys.add(self)
         # set up remote ".column" attribute, or a note to pick it
         # up when the other Table/Column shows up
<span class="pl-mdr">@@ -2124,6 +2126,8 @@</span> class ForeignKey(DialectKWArgs, SchemaItem):
             _column = self._colspec
             self._set_target_column(_column)
 
<span class="pl-mi1"><span class="pl-mi1">+</span>        if created:</span>
<span class="pl-mi1"><span class="pl-mi1">+</span>            self.constraint._set_parent_with_dispatch(table)</span>
 
 class DefaultGenerator(SchemaItem):
     """Base class for column *default* values."""</pre></div>
<p dir="auto">Otherwise, a least-side-effect-possible solution would be to detect the missing column inside of  <code class="notranslate">sqlalchemy.sql.naming.ConventionDict._key_referred_column_X_name</code>, and raise a clearer error. Something like this (pseudo-code, just to illustrate):</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="def _key_referred_column_X_name(self, idx):
    fk = self.const.elements[idx]
    try:
        return fk.column.name
    except NoReferencedColumnError as err:
        raise NamingConventionError(
            'Token column_0_name cannot be used with ForeignKey(str)'
        ) from err"><pre class="notranslate"><span class="pl-k">def</span> <span class="pl-en">_key_referred_column_X_name</span>(<span class="pl-s1">self</span>, <span class="pl-s1">idx</span>):
    <span class="pl-s1">fk</span> <span class="pl-c1">=</span> <span class="pl-s1">self</span>.<span class="pl-s1">const</span>.<span class="pl-s1">elements</span>[<span class="pl-s1">idx</span>]
    <span class="pl-k">try</span>:
        <span class="pl-k">return</span> <span class="pl-s1">fk</span>.<span class="pl-s1">column</span>.<span class="pl-s1">name</span>
    <span class="pl-k">except</span> <span class="pl-v">NoReferencedColumnError</span> <span class="pl-k">as</span> <span class="pl-s1">err</span>:
        <span class="pl-k">raise</span> <span class="pl-v">NamingConventionError</span>(
            <span class="pl-s">'Token column_0_name cannot be used with ForeignKey(str)'</span>
        ) <span class="pl-k">from</span> <span class="pl-s1">err</span></pre></div>
<p dir="auto"><strong>Versions</strong></p>
<ul dir="auto">
<li>OS: Manjaro Linux</li>
<li>Python: 3.8.2</li>
<li>SQLAlchemy: 1.3.16 + master (both for the bug and the ugly fix)</li>
<li>Database: None</li>
<li>DBAPI: None</li>
</ul>