我有一个 python 应用程序,它使用 postgres 9.1 和我相信的 sqlalchemy 0.7 在 2.7 版上运行。
我有一个 wx python gui,我可以从中添加和删除项目。代码运行良好,但现在在进行了一些修改后,我收到了
$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'}
现在,当我重新启动应用程序时,密钥 id 增加一。我可以清楚地看到某些东西正在重置数据库的 id 序列。请问anypne可以帮助我如何通过编写python代码来解决这个问题,或者解决这个问题的简单步骤是什么。我尝试通过 psql 命令工作,但由于我缺乏知识,我没有成功。如果解决方案可以用简单的步骤解释,那就太好了。