title: How to Create New Tables without Defined Classes in SQLAlchemy 1.2.7
body: <p>I am using SQLAlchemy's declarative API to build my models and tables for my application. </p>
  
  <p>However, I'm unable to use <code>Base.metadata.create_all(engine)</code> command to build a new table in my database because of error <code>NoReferencedTableError: Foreign key associated with column 'org_prediction.company_id' could not find table 'organization' with which to generate a foreign key to target column 'id'</code></p>
  
  <p>The reason this is happening is because the class Organization I am trying to reference for a ForeignKey does not exist in my models.py file. So, when I call <code>Base.metadata.create_all(engine)</code>, SQLAlchemy chokes because class Organization is not present in Base...</p>
  
  <p>I have tried reflecting my database, which will return the table for Organization which exists, but has no corresponding Class written for it in my models.py file. But when I reflect the DB tables and try to create my new dependent class on top of Organization, I get an error like: <code>InvalidRequestError: Table 'user' is already defined for this MetaData instance.  Specify 'extend_existing=True' to redefine options and columns on an existing Table object.</code>, which is caused because the reflected MetaData and my models.py class for User overlap, and SQLAlchemy isn't sure what to do. </p>
  
  <p>But where do I apply extend_existing=True? I have no Table objects to pass this parameter into. How can I create my FK dependent table when my FK dependent table doesn't exist in my models.py file? Or how can I reflect my existing tables, but append or update only the classes which do not exist yet in the database?</p>
  
  <p>models.py</p>
  
  <pre><code>from sqlalchemy.ext.declarative import declarative_base
  Base = declarative_base()
  
  class User(Base):
      __tablename__ = 'user'
      id = Column(Integer, primary_key=True)
      username = Column(String(50))
  
  class OrgPrediction(Base):
      __tablename__ = 'org_prediction'
      id = Column(Integer, primary_key=True)
      company_id = Column(String(255), ForeignKey('organization.id'), nullable=True)
      prediction = Column(String(255)
  Base.metadata.create_all(engine)
  </code></pre>
  
  <p>NoReferencedTableError: Foreign key associated with column 'org_prediction.company_id' could not find table 'organization' with which to generate a foreign key to target column 'id'</p>
  
  <p>MYSQL:</p>
  
  <pre><code>mysql&gt; desc organization;
  +-----------------------+------------+------+-----+---------+-------+
  | Field                 | Type       | Null | Key | Default | Extra |
  +-----------------------+------------+------+-----+---------+-------+
  | id                 | bigint(20) | YES  | MUL | NULL    |       |
  
  
  mysql&gt; show tables;
  +-------------------------+
  | Tables_in_database |
  +-------------------------+
  | organization            |
  | user                    |
  | user_email              |
  </code></pre>
  
  <p>In the case of Reflection the models.py file:</p>
  
  <pre><code>from sqlalchemy.ext.automap import automap_base
  from sqlalchemy import create_engine
  
  Base = automap_base()
  Base.prepare(engine, reflect=True)
  
  class User(Base):
      __tablename__ = 'user'
      id = Column(Integer, primary_key=True)
      username = Column(String(50))
  
  class OrgPrediction(Base):
      __tablename__ = 'org_prediction'
      id = Column(Integer, primary_key=True)
      company_id = Column(String(255), ForeignKey('organization.id'), nullable=True)
  
  Base.metadata.create_all(engine)
  </code></pre>
  
  <p>InvalidRequestError: Table 'user' is already defined for this MetaData instance.  Specify 'extend_existing=True' to redefine options and columns on an existing Table object.</p>