Hello there.
I've a problem with MySQLdb. I'm using version 0.9.2 (MySQL-python-0.9.2.win32-py2.2), with a 2.2.2 MySQL (for Windows).
The insert is done in a quite simple table that looks like this:
table datos (fecha timestamp(14), tipo varchar(255) not null, primary key(fecha,tipo))
The insert itself is something like this:
sql = "INSERT INTO datos (fecha,tipo) VALUES (%s,%s)"
run_sql(sql,(fecha,'arranque'))
Function "run_sql" basically connects to the db when the connection has not been done yet, and executes the query itself. The problem is that at first instance, the first insert works well, but when the program process others (while it is allready connected to the DB) it inserts well the data in the table, but raises a _mysql_exceptions.IntegrityError.
I've traced the program again and again, but the execute of the query is done only once, so I don't understand why it raises such an error. Any help will be appreciated :) Thank you in advance.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Your primary key is (fecha,tipo). IntegrityError will be raised if you try to insert the same value twice (the primary key is required to be unique and not null). The only other possibility is that you using a transaction-safe table type (BDB or InnoDB) and there are two conflicting inserts.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello there.
I've a problem with MySQLdb. I'm using version 0.9.2 (MySQL-python-0.9.2.win32-py2.2), with a 2.2.2 MySQL (for Windows).
The insert is done in a quite simple table that looks like this:
table datos (fecha timestamp(14), tipo varchar(255) not null, primary key(fecha,tipo))
The insert itself is something like this:
sql = "INSERT INTO datos (fecha,tipo) VALUES (%s,%s)"
run_sql(sql,(fecha,'arranque'))
Function "run_sql" basically connects to the db when the connection has not been done yet, and executes the query itself. The problem is that at first instance, the first insert works well, but when the program process others (while it is allready connected to the DB) it inserts well the data in the table, but raises a _mysql_exceptions.IntegrityError.
I've traced the program again and again, but the execute of the query is done only once, so I don't understand why it raises such an error. Any help will be appreciated :) Thank you in advance.
Your primary key is (fecha,tipo). IntegrityError will be raised if you try to insert the same value twice (the primary key is required to be unique and not null). The only other possibility is that you using a transaction-safe table type (BDB or InnoDB) and there are two conflicting inserts.