sqlalchemy empty schema and no tables
<p>I am trying to use sqlalchemy via a Database first approach and generate the models for the existing database structure. The db is a standard SQLServer(express).</p>

<p>I can connect to my database and query it via the following</p>

<pre><code>from sqlalchemy import create_engine, MetaData, Table
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.ext.declarative import declarative_base

__connectionString = "DSN=databaseDSN;Trusted_Connection=yes"

db_engine = create_engine('mssql+pyodbc:///?odbc_connect=%s' % __connectionString, echo=True)
db_session = scoped_session(sessionmaker(bind=db_engine))

result = db_session.execute("SELECT * FROM debug.BasicTable")
for row in result.fetchmany(10):
    print(row)
</code></pre>

<p>When I try to reflect the database structure below I am unable to see any of the actual tables and the following raises a NoSuchTableError </p>

<pre><code>myTable= Table('debug.BasicTable', meta, autoload=True, autoload_with=db_engine)
</code></pre>

<p>from a common tutorial <a href="http://pythoncentral.io/sqlalchemy-faqs/" rel="nofollow">http://pythoncentral.io/sqlalchemy-faqs/</a></p>

<p>I should be able to reflect the table objects </p>

<pre><code>Base = declarative_base()
Base.metadata.reflect(db_engine)

meta = MetaData()
meta.reflect(bind=db_engine)
</code></pre>

<p>However there are no table objects in meta.tables at all.</p>

<p>This is because <code>debug.BasicTable</code> is most likley not the name of your table. The name of your table is <code>BasicTable</code> and <code>debug</code> is its schema. So:</p>

<pre><code>Table('BasicTable', meta, schema="debug", autoload=True, autoload_with=db_engine)
</code></pre>

python sql-server sqlalchemy