Michael,

I had missed calling MetaData, but after making the call, I get the following 
traceback.

>>> from sqlalchemy import MetaData, create_engine, Table
>>> meta = MetaData()
>>> engine1 = create_engine("mssql+pyodbc://mydsn")
>>> valid_species_table = Table(
...   'tf_valid_species', meta, autoload = True, autoload_with = engine1)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/schema.py",
 line 210, in __new__
    table._init(name, metadata, *args, **kw)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/schema.py",
 line 258, in _init
    include_columns=include_columns)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1863, in reflecttable
    self.dialect.reflecttable(conn, table, include_columns)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/default.py",
 line 228, in reflecttable
    return insp.reflecttable(table, include_columns)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/reflection.py",
 line 382, in reflecttable
    for col_d in self.get_columns(table_name, schema, **tblkw):
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/reflection.py",
 line 229, in get_columns
    **kw)
  File "<string>", line 1, in <lambda>
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/reflection.py",
 line 46, in cache
    ret = fn(self, con, *args, **kw)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/dialects/mssql/base.py",
 line 1244, in get_columns
    c = connection.execute(s)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1191, in execute
    params)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1271, in _execute_clauseelement
    return self.__execute_context(context)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1302, in __execute_context
    context.parameters[0], context=context)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1401, in _cursor_execute
    context)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/base.py",
 line 1394, in _cursor_execute
    context)
  File 
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/SQLAlchemy-0.6.6-py2.7.egg/sqlalchemy/engine/default.py",
 line 299, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.ProgrammingError: (ProgrammingError) ('42000', '[42000] 
[Actual][SQL Server] The data types nvarchar and ntext are incompatible in the 
equal to operator. (402) (SQLExecDirectW)') u'SELECT 
[COLUMNS_1].[TABLE_SCHEMA], [COLUMNS_1].[TABLE_NAME], 
[COLUMNS_1].[COLUMN_NAME], [COLUMNS_1].[IS_NULLABLE], [COLUMNS_1].[DATA_TYPE], 
[COLUMNS_1].[ORDINAL_POSITION], [COLUMNS_1].[CHARACTER_MAXIMUM_LENGTH], 
[COLUMNS_1].[NUMERIC_PRECISION], [COLUMNS_1].[NUMERIC_SCALE], 
[COLUMNS_1].[COLUMN_DEFAULT], [COLUMNS_1].[COLLATION_NAME] \nFROM 
[INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1] \nWHERE [COLUMNS_1].[TABLE_NAME] 
= ? AND [COLUMNS_1].[TABLE_SCHEMA] = ? ORDER BY [COLUMNS_1].[ORDINAL_POSITION]' 
(u'tf_valid_species', u'dbo')

R. Mark Sharp, Ph.D.
[email protected]<mailto:[email protected]>




On Jan 24, 2011, at 6:25 PM, Michael Bayer wrote:


On Jan 24, 2011, at 5:45 PM, Mark Sharp wrote:

I am wanting to have SQLAlchemy pull the table schema from the database.   I 
have just started trying to work through Essential SQLAlchemy and believe that 
I am using a syntax that is no longer supported in SQLAlchemy 0.6.6. This what 
I have tried:
from sqlalchemy import MetaData, create_engine, Table
meta = MetaData
engine1 = create_engine("mssql+pyodbc://mydsn")
valid_species_table = Table('tf_valid_species', meta, autoload = True, 
autoload_with = engine1)

I get a traceback that indicates MetaData does not have an attribute 'tables' 
(see below).  Thus far, though I expect it exists, I have not found anything 
comparable within the 0.6.6

you need to construct the "MetaData":

meta = MetaData()

otherwise the example looks OK.


--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to 
[email protected]<mailto:[email protected]>.
To unsubscribe from this group, send email to 
[email protected]<mailto:[email protected]>.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to