Skip to content

Instantly share code, notes, and snippets.

@edthix
Created January 3, 2014 13:17
Show Gist options
  • Save edthix/8237702 to your computer and use it in GitHub Desktop.
Save edthix/8237702 to your computer and use it in GitHub Desktop.
# Run in idle (Windows 7, python 2.7) everything ok until table definition
>>> from sqlalchemy import create_engine, MetaData
>>> from sqlalchemy.orm import scoped_session, sessionmaker
# user/password/database I put it wrongly since this is public
>>> engine = create_engine('mssql+pyodbc://plast@user:password@database', convert_unicode=True, implicit_returning=False)
>>> metadata = MetaData(bind=engine)
>>> db_session = scoped_session(sessionmaker(autocommit=False,
autoflush=False,
bind=engine))
>>> def init_db():
metadata.create_all(bind=engine)
>>> from sqlalchemy import Table, Column, Integer, String
>>> from sqlalchemy.orm import mapper, relationship, backref
>>> class Block(object):
query = db_session.query_property()
>>> BlockTable = Table('blocks', metadata, autoload=True, implicit_returning=False)
Traceback (most recent call last):
File "<pyshell#16>", line 1, in <module>
BlockTable = Table('blocks', metadata, autoload=True, implicit_returning=False)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 332, in __new__
table._init(name, metadata, *args, **kw)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 396, in _init
self._autoload(metadata, autoload_with, include_columns)
File "C:\Python27\lib\site-packages\sqlalchemy\schema.py", line 424, in _autoload
self, include_columns, exclude_columns
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1595, in run_callable
return conn.run_callable(callable_, *args, **kwargs)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\base.py", line 1118, in run_callable
return callable_(self, *args, **kwargs)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\default.py", line 262, in reflecttable
return insp.reflecttable(table, include_columns, exclude_columns)
File "C:\Python27\lib\site-packages\sqlalchemy\engine\reflection.py", line 440, in reflecttable
raise exc.NoSuchTableError(table.name)
NoSuchTableError: blocks
>>>
# Why NoSuchTable?
# Pip list
# C:\Users\ed>pip list
# Flask (0.10.1)
# Flask-HTTPAuth (2.1.0)
# Flask-RESTful (0.2.5)
# Flask-Storage (0.1.0)
# httpauth (0.2)
# itsdangerous (0.23)
# Jinja2 (2.7.1)
# MarkupSafe (0.18)
# MySQL-python (1.2.3)
# pip (1.4.1)
# pyodbc (3.0.7)
# setuptools (1.1)
# six (1.4.1)
# SQLAlchemy (0.8.2)
# Werkzeug (0.9.4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment