產生我無法執行以下代碼,顯然這些語句是代碼的一部分。鍵'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不要總是插在一起,並按順序。儘管如此,這看起來並不是那種情況之一。 –