title: SQLAlchemy: AttributeError: 'Table' object has no attribute 'id'
body: <p>I'm building a DB, that matches my local product catalogue with foreign ones. When I had the only table <code>'Catalog'</code> SQLAlchemy worked fine. After adding tables <code>Competitors</code> and <code>Competitors_catalog</code> all my attempts to add records to both new tables returned with error.</p>
  <blockquote>
  <h3>AttributeError: 'Table' object has no attribute 'id'</h3>
  </blockquote>
  <p>I change/remove/play with relationship between <code>Competitors</code> and <code>Competitors_catalog</code> several times, drop and create tables through <code>flask-migrate</code> back and forth, but keep receiving same error.
  Simple query like <code>Competitors.query.all()</code> returns the same.
  Removed <code>db.relationship()</code> - same result.
  Then I finally rolled back to a clear db and initiated it with <code>flask-migrate</code> from scratch. After that I begin to receive same error trying to add records to <code>Catalog</code> table, which worked fine before I rolled back. Which is odd since I made no changes to that part of the code.</p>
  <pre class="lang-py prettyprint-override"><code>class Catalog(db.Model):
      __tablename__ = 'catalog'
  
      id            = db.Column(db.Integer, primary_key=True)
      name          = db.Column(db.String(60), index=True, nullable=False)
      parent_id     = db.Column(db.Integer, db.ForeignKey('catalog.id'), default=None)
      url           = db.Column(db.String())
      created       = db.Column(db.DateTime, default=datetime.now())
      last_modified = db.Column(db.DateTime, index=True, onupdate=datetime.now())
  
      categories = db.relationship('Catalog', remote_side='catalog.id', backref='parent')
  
  class Competitors(db.Model):
      __tablename__ = 'competitors'
  
      id            = db.Column(db.Integer, primary_key=True)
      name          = db.Column(db.String(40), index=True, nullable=False)
      base_url      = db.Column(db.String())
      cat_url       = db.Column(db.String())
      created       = db.Column(db.DateTime, default=datetime.now())
      last_modified = db.Column(db.DateTime, onupdate=datetime.now(), default=datetime.now())
  
      sells = db.relationship('Competitors_catalog', backref='competitor', cascade=&quot;all, delete-orphan&quot;, passive_deletes=True, lazy='dynamic')
  
  class CompCatalog(db.Model):
      __tablename__ = 'compcatalog'
  
      id            = db.Column(db.Integer, primary_key=True)
      out_id        = db.Column(db.Integer)
      name          = db.Column(db.String(60), index=True, nullable=False)
      top_section   = db.Column(db.Integer, default=None)
      comp_id       = db.Column(db.Integer, db.ForeignKey('competitors.id', ondelete=&quot;CASCADE&quot;))
      url           = db.Column(db.String())
      created       = db.Column(db.DateTime, default=datetime.now())
      last_modified = db.Column(db.DateTime, index=True, onupdate=datetime.now())
  </code></pre>
  <p>Simple creation of new instance returns error. But worked fine before roll back.</p>
  <pre class="lang-py prettyprint-override"><code>from .models import Catalog
  
  name = 'Apple'
  rec = Catalog(name=name)
  </code></pre>
  <pre><code>Traceback (most recent call last):
    File &quot;&lt;console&gt;&quot;, line 1, in &lt;module&gt;
    File &quot;.../app/helpers.py&quot;, line 31, in create_catalog
      rec = Catalog(name=name)
    File &quot;&lt;string&gt;&quot;, line 2, in __init__
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/instrumentation.py&quot;, line 376, in _new_state_if_none
      state = self._state_constructor(instance, self)
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/util/langhelpers.py&quot;, line 855, in __get__
      obj.__dict__[self.__name__] = result = self.fget(obj)
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/instrumentation.py&quot;, line 202, in _state_constructor
      self.dispatch.first_init(self, self.class_)
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/event/attr.py&quot;, line 322, in __call__
      fn(*args, **kw)
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/mapper.py&quot;, line 3360, in _event_on_first_init
      configure_mappers()
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/mapper.py&quot;, line 3248, in configure_mappers
      mapper._post_configure_properties()
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/mapper.py&quot;, line 1947, in _post_configure_properties
      prop.init()
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/interfaces.py&quot;, line 196, in init
      self.do_init()
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/relationships.py&quot;, line 1860, in do_init
      self._process_dependent_arguments()
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/orm/relationships.py&quot;, line 1889, in _process_dependent_arguments
      setattr(self, attr, attr_value())
    File &quot;.../.virtualenvs/.../lib/python3.6/site-packages/sqlalchemy/ext/declarative/clsregistry.py&quot;, line 294, in __call__
      x = eval(self.arg, globals(), self._dict)
    File &quot;&lt;string&gt;&quot;, line 1, in &lt;module&gt;
  AttributeError: 'Table' object has no attribute 'id'
  </code></pre>