Hi,
I'm a nerb with SQLAlchemy, so this is probably a silly question, but
here goes. I have a table in SQL Server V.8 where I am trying to
insert a row. Here's most of my code:
<code>
from sqlalchemy import *
db = dbConnect() # function to connect to my db
db.echo = True
metadata = MetaData(db)
entries = Table('tbl_TimeEntries', metadata,
Column('dateworked', String(10),
primary_key=True),
Column('empid', Integer, primary_key=True),
Column('reg', Float),
Column('ot', Float),
Column('ce', Float),
Column('hol', Float),
Column('sklv', Float),
Column('vac', Float),
Column('ct', Float),
Column('conv', Float),
Column('misc', Float),
Column('comments', Unicode(256))
)
i = entries.insert(values={'dateworked':'02/13/2008', 'empid':258,
'reg':8.00})
</code>
Unfortunately, this results in the following traceback:
Traceback (most recent call last):
File "//someServer/Scripts/PythonPackages/Development/Timesheet/
sqlalchemy-test2.py", line 48, in -toplevel-
main(tblName, key, val)
File "//someServer/Scripts/PythonPackages/Development/Timesheet/
sqlalchemy-test2.py", line 28, in main
i.execute()
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\sql\expression.py", line 992, in execute
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\engine\base.py", line 1211, in execute_clauseelement
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\engine\base.py", line 895, in execute_clauseelement
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\engine\base.py", line 906, in _execute_compiled
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\engine\default.py", line 278, in pre_execution
File "c:\python24\lib\site-packages\SQLAlchemy-0.4.2b-py2.4.egg
\sqlalchemy\databases\mssql.py", line 322, in pre_exec
File "C:\Python24\lib\site-packages\pymssql.py", line 126, in
execute
self.executemany(operation, (params,))
File "C:\Python24\lib\site-packages\pymssql.py", line 152, in
executemany
raise DatabaseError, "internal error: %s" % self.__source.errmsg()
DatabaseError: internal error: SQL Server message 8106, severity 16,
state 1, line 1:
Table 'tbl_TimeEntries' does not have the identity property. Cannot
perform SET operation.
DB-Lib error message 10007, severity 5:
General SQL Server error: Check messages from the SQL Server.
Upon digging in Google and Microsoft's pages, it seems that SQLAlchemy
is trying to use the SET IDENTITY_INSERT setting for a column that
doesn't have this setting. Why is it doing that in the first place and
how to I stop that behavior?
Also, as you may notice, I have two columns set as the primary key. Is
that the correct way to create a composite primary key?
Any tips are appreciated. I apologize for the lengthy post. I am
programming with Python 2.4 and SQLAlchemy-0.4.2b on Windows XP.
Thanks,
Mike
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---