- changed status to wontfix
Cannot create tables in SQLite
Hi, starting with new version of SQLAlchemy, 0.3.5, the following code failed to create a table in sqlite. The code was working with version 0.3.4. Also, the code works fine with MySQL.
#!/usr/bin/env python
# system modules
import sys, string, time, types
from sqlalchemy import *
engine = create_engine('sqlite:///sqlite.db', echo=True)
#
tableList = [= Sequence(name='seq_user',start=1,increment=True)
t_user = Table('t_user', engine,
Column('id', Integer, Sequence('seq_user'), nullable = False, primary_key = True),
Column('userid', String(60), nullable = False, unique=True)
)
tableList.append(t_user)
#
seq_command = Sequence(name='seq_command',start=1,increment=True)
t_command = Table('t_command', engine,
Column('id', Integer, Sequence('seq_command'), nullable = False, primary_key = True),
Column('command', String(1000))
)
tableList.append(t_command)
#
seq_history = Sequence(name='seq_history',start=1,increment=True)
t_history = Table('t_history', engine,
Column('id', Integer, Sequence('seq_history'), nullable = False, primary_key = True),
Column('userid', Integer, ForeignKey("t_user.id"), nullable = False),
Column('cmdid', Integer, ForeignKey("t_command.id"), nullable = False),
Column('date', Date, onupdate=func.current_timestamp()),
Column('time', Time, onupdate=func.current_timestamp())
)
tableList.append(t_history)
#
# main
#
if __name__ == "__main__":
tableList.reverse()
for table in tableList:
print "Drop table",table
try:
table.drop()
except:
pass
tableList.reverse()
for table in tableList:
print table,type(table)
try:
table.create()
except:
sys.excepthook(sys.exc_info()[0](]
#
seq_user),sys.exc_info()[1](1),sys.exc_info()[2](2))
raise "Fail to create %s"%table.name
The traceback: Traceback (most recent call last): File "/Users/vk/testSQLA.py", line 49, in ? table.create() File "/opt/local/lib/python2.4/site-packages/sqlalchemy/schema.py", line 326, in create self.engine.create(self, checkfirst=checkfirst) File "/opt/local/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 402, in create self._run_visitor(self.dialect.schemagenerator, entity, connection=connection, kwargs) File "/opt/local/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 426, in _run_visitor element.accept_schema_visitor(visitorcallable(self, conn.proxy, connection=conn, kwargs)) File "/opt/local/lib/python2.4/site-packages/sqlalchemy/schema.py", line 279, in accept_schema_visitor return visitor.visit_table(self) File "/opt/local/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 635, in visit_table self.append("\t" + self.get_column_specification(column, first_pk=column.primary_key and not first_pk)) File "/opt/local/lib/python2.4/site-packages/sqlalchemy/databases/sqlite.py", line 284, in get_column_specification colspec = self.preparer.format_column(column) + " " + column.type.engine_impl(self.engine).get_col_spec() File "/opt/local/lib/python2.4/site-packages/sqlalchemy/types.py", line 51, in get_col_spec raise NotImplementedError() NotImplementedError Traceback (most recent call last): File "/Users/vk/testSQLA.py", line 52, in ? raise "Fail to create %s"%table.name Fail to create t_history
Thanks, Valentin.
Comments (1)
-
repo owner - Log in to comment
based on looking at your stack trace, I suspect you have to uninstall an old version of SQLAlchemy, since setuptools will create a path something like
/site-packages/SQLAlchemy-0.3.5-py2.4.egg/sqlalchemy/__init__.pyc
for most versions. Additionally, line 51 of types.py is nowhere near the code described by the traceback.using SA 0.3.5 as well as the latest trunk (+ very recent sqlite/pysqlite), I get this output: