1

I have got an python application which runs on version 2.7 using postgres 9.1 with sqlalchemy 0.7 i believe.

I have a wx python gui from which i add and delete items.The code was working fine but now after making some modifications i recieve

$self.session.commit()
$  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 645, in commit
$  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 313, in commit
$  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 297, in _prepare_impl
$  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 1547, in flush
$  File "build\bdist.win32\egg\sqlalchemy\orm\session.py", line 1616, in _flush
$  File "build\bdist.win32\egg\sqlalchemy\orm\unitofwork.py", line 328, in execute
$  File "build\bdist.win32\egg\sqlalchemy\orm\unitofwork.py", line 472, in execute
$  File "build\bdist.win32\egg\sqlalchemy\orm\mapper.py", line 2291, in _save_obj
$  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1405, in execute
$ File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1538, in           
$ _execute_clauseelement
$  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1646, in     
$_execute_context
$  File "build\bdist.win32\egg\sqlalchemy\engine\base.py", line 1639, in 
$_execute_context
$  File "build\bdist.win32\egg\sqlalchemy\engine\default.py", line 330, in do_execute
$sqlalchemy.exc.IntegrityError: (IntegrityError) duplicate key value violates
$ unique constraint "Equipment_pkey"
$DETAIL:  Key (id)=(4) already exists.
$ 'INSERT INTO "Equipment" (name, "numPorts") VALUES (%(name)s, %(numPorts)s)     
$RETURNING "HWCIs".id' {'numPorts': 0, 'name': u'jkhj'}

Now when i restart the application the key id increases by one.I can clearly see that something is resetting the id sequence of the database. Could anypne please help on how i can fix this issue by writing python code or what is the easiet step to overcome this issue . I tried working through psql commands but i was unsuccessful due to my lack of knowledge.If solution can explained in easy steps that would be great.

2 Answers 2

1

Well I found the answer. I was conencting to another database connection which caused the database sequence to reset to 1. So when application starts it seeks to position 1. So I just needed to change the sequence to last no. It worked!

Sign up to request clarification or add additional context in comments.

Comments

0

There is everything in the logs:

You are inserting a row with id=4 but there is already row with this id.

Do you have the row with id=4 in the table?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.