<p>For others' reference, if you are using schemas (e.g. Postgres) you might also have to specify it:</p>
<pre class="lang-py prettyprint-override"><code># Assumes tables live in schema `my_schema`

arxiv_id = db.Column(db.String(1000), db.ForeignKey('my_schema.papers.arxiv_id'))
</code></pre>
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column X could not find table Y with which to generate a foreign key
<p>I get the following error in my sqlalchemy schema</p>

<pre><code>python manage.py db migrate
...
sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 
'ArxivPaperFigure.arxiv_id' could not find table 'papers' with which to 
generate a foreign key to target column 'arxiv_id' 
</code></pre>

<p>I do not understand this error since the table papers is not new but existed before. I made a lot of changes, including giving the papers table a new table to inherit from, but the primary key in papers is still the same arxiv_id. Here is my papers table </p>

<pre><code>class Papers(db.Model, Paper): 

    arxiv_id = db.Column(db.String(1000), primary_key=True)
    ...
</code></pre>

<p>and the table which points to this table is </p>

<pre><code>class ArxivPaperFigure(db.Model): 
    __tablename__ = 'ArxivPaperFigure'

    id = db.Column(db.Integer, primary_key=True)
    arxiv_id = db.Column(db.String(1000), db.ForeignKey('papers.arxiv_id'))
</code></pre>

<p>I can solve the issue by re-writing the Foreign key</p>

<pre><code>arxiv_id = db.Column(db.String(1000), db.ForeignKey(Papers.arxiv_id))
</code></pre>

<p>However, I have a lot of foreign keys and for some tables which also have these foreign keys this solution does not work. So I would like to understand why this error appears? The papers table does exist. If I use psql and print all tables with \d I find the line</p>

<pre><code>public | papers  | table    | user
</code></pre>

<p>so why does this reference not work anymore?</p>