I am having trouble to execute following code, obviously these statement are part of the code.
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
Error generated is
IntegrityError: ('23000', "[23000] [MySQL][ODBC 5.1 Driver][mysqld-5.1.61-community]Duplicate entry '1' for key 'PRIMARY' (1062) (SQLExecDirectW)")
I read previous attempts by different user to to solve the problem but for me nothing worked out.
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)
After all of yours helpful suggestion I used following statement
cursor.execute("INSERT INTO tblauto_tagged(tagger,train,propernoun,propernoun_ID) VALUES (?,?,?,?)",(str(iput),str(corpora),str(nnp_array[add1:add2]),0))
And I ran into another trouble and for sure today is not my day.In order to make my problem more clear, I am editing the question with some additional information. ever thing works fine till 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 |
+-----------------+--------+-------+------------------------------------------------------------------------------------------------------------+---------------+
and after propernoun_SRNO = 150 this is what I get.
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)
which goes all the way down to 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)
I don’t know what the problem is but I think it needs some experts opinion. As mentioned in the previous comments should I use sequences, please advice
To explain zerkms’s comment: You are trying to insert a row with a value for the primary key (
propernoun_SRNO, if I’m not mistaken) which is already in use.If you are trying to insert all new rows to the database, don’t specify a value for the primary key, and MySQL should calculate one automatically, assuming that the column is set as
AUTO_INCREMENT.If you are trying to replace existing rows with these IDs, use
REPLACEinstead ofINSERT, or delete the existing rows before you insert new ones.