Using this schema:
DROP TABLE IF EXISTS poll_basic_results;
CREATE TABLE poll_basic_results (
rid INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
pid INT UNSIGNED NOT NULL DEFAULT 0,
uid INT UNSIGNED NOT NULL DEFAULT 0,
answer INT UNSIGNED NOT NULL DEFAULT 0,
timestamp INT UNSIGNED NOT NULL DEFAULT 0,
code VARCHAR(32) NOT NULL DEFAULT '',
zip VARCHAR(16) NOT NULL DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE UNIQUE INDEX rid_pid ON poll_basic_results (rid, pid);
This code is supposed to populate the table, with 1000 rows of random choices made.
$time = time();
$pid = arg(2, 'int');
$poll = new Poll($pid);
$max = 2;
if ($poll->getAnswer3() != '') {
$max = 3;
}
if ($poll->getAnswer4() != '') {
$max = 4;
}
for ($i = 0; $i < 1000; $i++) {
$result = new PollBasicResult;
$result->setPid($pid);
$result->setAnswer(fCryptography::random(1, $max));
$result->setTimestamp($time);
$result->store();
}
Base_Router::route('poll/'.$pid);
}
catch (fNotFoundException $e) {
Base_Router::route('404');
}
catch (fValidationException $e) {
die($e->getMessage());
}
But I get this error:
#!text/html
Rid, Pid: The values specified must be a unique combination, however the specified combination already exists
Yet, I can insert new rows manually with the same Pid, because Rid is auto-incrementing:
#!text/html
mysql> INSERT INTO poll_basic_results (pid, uid, answer, timestamp) VALUES(40, 0, 1, UNIX_TIMESTAMP());
Query OK, 1 row affected (0.01 sec)
mysql> INSERT INTO poll_basic_results (pid, uid, answer, timestamp) VALUES(40, 0, 1, UNIX_TIMESTAMP());
Query OK, 1 row affected (0.00 sec)
mysql> INSERT INTO poll_basic_results (pid, uid, answer, timestamp) VALUES(40, 0, 1, UNIX_TIMESTAMP());
Query OK, 1 row affected (0.01 sec)
No problem over and over again. Why is the code attempting to assign Rid? Even passing NULL (as phpMyAdmin does) doesn't do anything ($result->setRid(NULL);).