我无法执行以下代码,显然这些语句是代码的一部分。
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))
我又遇到了一个麻烦,今天肯定不是我的日子。为了让我的问题更清楚,我正在用一些额外的信息编辑这个问题。在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)
我不知道问题是什么,但我认为这需要一些专家的意见。正如前面的评论中提到的,我应该使用序列,请指教