<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">Without the foreign key, it works fine and with sqlite instead of postgres, it works fine too.</p>
<p dir="auto">See attached file for a test case.</p>
<p dir="auto">It fails with the following traceback:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Traceback (most recent call last):
  File &quot;test_autoload.py&quot;, line 20, in &lt;module&gt;
    meta2.create_all()   # this fails.
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/schema.py&quot;, line 1147, in create_all
    connectable.create(self, checkfirst=checkfirst, tables=tables)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 681, in create
    self._run_visitor(self.dialect.schemagenerator, entity, connection=connection, **kwargs)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 711, in _run_visitor
    element.accept_visitor(visitorcallable(conn, **kwargs))
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/schema.py&quot;, line 1169, in accept_visitor
    visitor.visit_metadata(self)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/ansisql.py&quot;, line 805, in visit_metadata
    table.accept_visitor(self)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/sql.py&quot;, line 2095, in accept_visitor
    visitor.visit_table(self)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/ansisql.py&quot;, line 840, in visit_table
    self.execute()
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 1179, in execute
    return self.connection.execute(self.buffer.getvalue())
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 502, in execute
    return Connection.executors[c](c)(self, object, *multiparams, **params)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 517, in execute_text
    self._execute_raw(context)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 566, in _execute_raw
    self._execute(context)
  File &quot;/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py&quot;, line 583, in _execute
    raise exceptions.SQLError(context.statement, context.parameters, e)
sqlalchemy.exceptions.SQLError: (ProgrammingError) syntax error at or near &quot;$1&quot;
LINE 6:   CONSTRAINT $1 FOREIGN KEY(test_id) REFERENCES test (id)
                     ^
 &quot;\nCREATE TABLE test (\n\tid INTEGER DEFAULT nextval('public.test_id_seq'::text) NOT NULL, \n\ttest_id INTEGER, \n\tPRIMARY KEY (id), \n\t CONSTRAINT $1 FOREIGN KEY(test_id) REFERENCES test (id)\n)\n\n&quot; {}"><pre class="notranslate"><code class="notranslate">Traceback (most recent call last):
  File "test_autoload.py", line 20, in &lt;module&gt;
    meta2.create_all()   # this fails.
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/schema.py", line 1147, in create_all
    connectable.create(self, checkfirst=checkfirst, tables=tables)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 681, in create
    self._run_visitor(self.dialect.schemagenerator, entity, connection=connection, **kwargs)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 711, in _run_visitor
    element.accept_visitor(visitorcallable(conn, **kwargs))
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/schema.py", line 1169, in accept_visitor
    visitor.visit_metadata(self)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/ansisql.py", line 805, in visit_metadata
    table.accept_visitor(self)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/sql.py", line 2095, in accept_visitor
    visitor.visit_table(self)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/ansisql.py", line 840, in visit_table
    self.execute()
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 1179, in execute
    return self.connection.execute(self.buffer.getvalue())
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 502, in execute
    return Connection.executors[c](c)(self, object, *multiparams, **params)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 517, in execute_text
    self._execute_raw(context)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 566, in _execute_raw
    self._execute(context)
  File "/home/ged/devel/sqlalchemy/lib/sqlalchemy/engine/base.py", line 583, in _execute
    raise exceptions.SQLError(context.statement, context.parameters, e)
sqlalchemy.exceptions.SQLError: (ProgrammingError) syntax error at or near "$1"
LINE 6:   CONSTRAINT $1 FOREIGN KEY(test_id) REFERENCES test (id)
                     ^
 "\nCREATE TABLE test (\n\tid INTEGER DEFAULT nextval('public.test_id_seq'::text) NOT NULL, \n\ttest_id INTEGER, \n\tPRIMARY KEY (id), \n\t CONSTRAINT $1 FOREIGN KEY(test_id) REFERENCES test (id)\n)\n\n" {}
</code></pre></div>
<p dir="auto"><strong>Migrated issue, originally created by Anonymous</strong></p>
<p dir="auto">I searched existing open issues tagged with mssql but didn't see this one. Please close it if it's a duplicate.</p>
<p dir="auto">~Matt</p>
<p dir="auto">Pylons 0.9.7, SQLAlchemy 0.5.x, OSX 10.5, iodbc, freetds, remote MSSQL Server instance</p>
<p dir="auto">test.py contains:</p>
<p dir="auto">engine = create_engine("mssql://mdoar:<a href="mailto:secretword@hostname.example.com">secretword@hostname.example.com</a>:1433/my_database?driver=TDS&amp;odbc_options='TDS_Version=7.0'")</p>
<h1 dir="auto">This breaks with the attached backtrace</h1>
<p dir="auto">meta = schema.MetaData(engine, reflect=True)</p>
<h1 dir="auto">but this works fine:</h1>
<h1 dir="auto">meta = schema.MetaData(engine, reflect=False)</h1>
<p dir="auto">File "/Users/mdoar/atlassian/jira/commercial/venv_0.9.7/lib/python2.5/site-packages/SQLAlchemy-0.4.7p1-py2.5.egg/sqlalchemy/engine/base.py", line 907, in _execute_compiled<br>
self.__execute_raw(context)<br>
File "/Users/mdoar/atlassian/jira/commercial/venv_0.9.7/lib/python2.5/site-packages/SQLAlchemy-0.4.7p1-py2.5.egg/sqlalchemy/engine/base.py", line 916, in __execute_raw<br>
self._cursor_execute(context.cursor, context.statement, context.parameters<a href="0">0</a>, context=context)<br>
File "/Users/mdoar/atlassian/jira/commercial/venv_0.9.7/lib/python2.5/site-packages/SQLAlchemy-0.4.7p1-py2.5.egg/sqlalchemy/engine/base.py", line 960, in _cursor_execute<br>
self._handle_dbapi_exception(e, statement, parameters, cursor)<br>
File "/Users/mdoar/atlassian/jira/commercial/venv_0.9.7/lib/python2.5/site-packages/SQLAlchemy-0.4.7p1-py2.5.egg/sqlalchemy/engine/base.py", line 942, in _handle_dbapi_exception<br>
raise exceptions.DBAPIError.instance(statement, parameters, e, connection_invalidated=is_disconnect)<br>
sqlalchemy.exceptions.ProgrammingError: (ProgrammingError) ('The SQL contains 0 parameter markers, but 1 parameters were supplied', 'HY000') u'SELECT tables_1.table_name \nFROM information_schema.tables AS tables_1 \nWHERE tables_1.table_schema = ?' <a href="'dbo'">'dbo'</a></p>
<hr>
<p dir="auto">Attachments: <a href="../wiki/imported_issue_attachments/1312/add_flag.patch">add_flag.patch</a></p>