产生我无法执行以下代码,显然这些语句是代码的一部分。键'PRIMARY'的重复条目'1'没有解决修复TABLE
cursor.execute("select max(propernoun_SRNO) from tblauto_tagged")
starting_index = cursor.fetchone()[0]
if starting_index == None :
starting_index = 1
ending_index = int(starting_index) +len(s)
i = 0
for j in range(starting_index,ending_index):
for i in range(0,len(s)):
c.append(nnp_array_index_coloumn.count(i))
add1 = add1 + c[i-1]
add2 = add1 + c[i]
cursor.execute("INSERT INTO tblauto_tagged(propernoun_SRNO,tagger,train,propernoun,propernoun_ID) VALUES (?,?,?,?,?)",(j,str(iput),str(corpora),str(nnp_array[add1:add2]),0))
for item in nnp_array_index_coloumn:
if item not in uniques:
uniques.append(item)
add1=0;add2=0
错误是
IntegrityError: ('23000', "[23000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]Duplicate entry '1' for key 'PRIMARY' (1062) (SQLExecDirectW)")
我看了以前的尝试不同的用户来解决这个问题,但对我来说毫无效果的。
mysql> repair table tblauto_tagged;
+--------------------------------+--------+----------+--------------------------------- ------------------------+
| Table | Op | Msg_type | Msg_text |
+--------------------------------+--------+----------+---------------------------------------------------------+
| collegedatabase.tblauto_tagged | repair | note | The storage engine for the table doesn't support repair |
+--------------------------------+--------+----------+---------------------------------------------------------+
1 row in set (0.00 sec)
mysql> select * from tblauto_tagged;
Empty set (0.00 sec)
你所有的有益的建议后,我用下面的语句
cursor.execute("INSERT INTO tblauto_tagged(tagger,train,propernoun,propernoun_ID) VALUES (?,?,?,?)",(str(iput),str(corpora),str(nnp_array[add1:add2]),0))
我遇到了另一个麻烦,今天肯定不是我day.In为了让我的问题更清楚,我正在编辑一些附加信息的问题。以往的事情工作正常,直到propernoun_SRNO = 149
mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =149;
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
| propernoun_SRNO | tagger | train | propernoun | propernoun_ID |
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
| 149 | 1 | 1 | ['Wing', 'tank', 'Hopper', 'BU', 'crewmember', 'beam', 'injured', 'Drug', 'Serious', 'Marine', 'Incident'] | 0 |
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
和propernoun_SRNO = 150之后,这是我所得到的。
mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =150;
+-----------------+--------+-------+------------+---------------+
| propernoun_SRNO | tagger | train | propernoun | propernoun_ID |
+-----------------+--------+-------+------------+---------------+
| 150 | 1 | 1 | [] | 0 |
+-----------------+--------+-------+------------+---------------+
1 row in set (0.00 sec)
肚里一路下跌到propernoun_SRNO = 22201
mysql> select max(propernoun_SRNO) from tblauto_tagged;
+----------------------+
| max(propernoun_SRNO) |
+----------------------+
| 22201 |
+----------------------+
1 row in set (0.00 sec)
mysql> select propernoun_SRNO ,tagger, train,propernoun,propernoun_ID from tblauto_tagged where propernoun_SRNO =22201;
+-----------------+--------+-------+------------+---------------+
| propernoun_SRNO | tagger | train | propernoun | propernoun_ID |
+-----------------+--------+-------+------------+---------------+
| 22201 | 1 | 1 | [] | 0 |
+-----------------+--------+-------+------------+---------------+
1 row in set (0.00 sec)
我不知道是什么问题,但我认为它需要一些专家的意见。正如先前的评论我应该用序列所提到的,请指教
**从不**手动计算下一个PK值。改为使用自动增量列或序列。 – zerkms
@zerkems,+1,但有系统(坏系统,但你必须忍受的系统),例如,多个表都使用相同的ID作为他们的PK,而不是用FKs做正确的方式,但aren不要总是插在一起,并按顺序。尽管如此,这看起来并不是那种情况之一。 –