I'm trying to create a MySQL user table that stores a randomly
generated 10-digit user id as its primary key. I'm going nuts though
cuz I keep getting 'Duplicate entry' errors even on numbers I know
are not in the table!
Here's what I've done. First I created the table with the index like
this:
CREATE TABLE user(
user_id INTEGER(10) UNSIGNED NOT NULL, [... rest of columns],
primary key(user_id)
);
Second, I generate a 10-digit random number with mtsrand then I run a
select statement on the user table to see if the number already
exists. If so, I generate another. Otherwise, I insert it into the
table.
The problem is after every 3 or 4 inserts, I get a 'Duplicate entry'
error on the primary key. But when I echo the random number I
generated, I see it's not in the column at all!
For example, I got 4294967295 to insert correctly. But then
6406330925 gives me an error when I know it's not an existing index.
Some numbers work and some don't. I can't figure out why that is.
I've tried dropping and recreating the tables. I've even tried
myisamchk to see if the tables are corrupt. But it still happens.
Can someone help?