Thanks. The traceback and sample code is as below:

TRACEBACK
---------------------
500 Internal error

The server encountered an unexpected condition which prevented it from
fulfilling the request.

Page handler: <bound method Root.createsanjay of <ierr.controllers.Root
object at 0xb763220c>>
Traceback (most recent call last):
  File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 105, in _run
    self.main()
  File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 254, in main
    body = page_handler(*virtual_path, **self.params)
  File "<string>", line 3, in createsanjay
  File
"/usr/lib/python2.4/site-packages/TurboGears-0.9a7-py2.4.egg/turbogears/controllers.py",
line 331, in expose
    output = database.run_with_transaction(
  File "<string>", line 5, in run_with_transaction
  File
"/usr/lib/python2.4/site-packages/TurboGears-0.9a7-py2.4.egg/turbogears/database.py",
line 268, in sa_rwt
    transaction.commit()
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line 46,
in commit
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/session.py", line
234, in flush
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
192, in flush
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
363, in execute
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
631, in execute
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/unitofwork.py", line
585, in _save_objects
  File "build/bdist.linux-i686/egg/sqlalchemy/orm/mapper.py", line 824,
in save_obj
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 244, in execute
    return Connection.executors[type(object).__mro__[-2]](self, object,
*multiparams, **params)
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 268, in execute_clauseelement
    return self.execute_compiled(elem.compile(engine=self.__engine,
parameters=param), *multiparams, **params)
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 284, in execute_compiled
    proxy(str(compiled), parameters)
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 280, in proxy
    self._execute_raw(statement, parameters, cursor=cursor,
context=context)
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 319, in _execute_raw
    self._execute(cursor, statement, parameters, context=context)
  File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.2.6-py2.4.egg/sqlalchemy/engine/base.py",
line 338, in _execute
    raise exceptions.SQLError(statement, parameters, e)
SQLError: (IntegrityError) ERROR:  duplicate key violates unique
constraint "ux_person_name"

INSERT INTO person (id, name) VALUES (7, 'sanjay') 'INSERT INTO person
(id, name) VALUES (%(id)s, %(name)s)' {'id': 7L, 'name': 'sanjay'}

APPLICATION
---------------------
#created a project using "tg-admin quickstart --sqlalchemy"

# model.py

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
from turbogears.database import metadata, session

person_table = Table('person', metadata,
        Column('id', Integer, primary_key=True),
        Column('name', String(30), unique=True, nullable=False)
)

class Person(object):
    pass

assign_mapper(session.context, Person, person_table)

#created a postgresql database; put a row with name 'sanjay'; edited
dev.cfg

# added the following method to root controller

    @expose()
    def createsanjay(self):
        try:
            sanjay = Person(name='sanjay')
            #sanjay.flush()                   does not work even after
commenting this line!
        except:
            return "Can not insert"
        return "Inserted!"

tried http://localhost:8080/createsanjay and got the traceback

Thanks
Sanjay


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" 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/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to