Monday, January 27, 2014

Re: failure of auto increment in inndb (mysql)

Den 27/01/2014 kl. 20.13 skrev Tom Lockhart <tlockhart1976@gmail.com>:

>> ...
>> Now Jane Smith has the same ID as John Doe had previously. This may not be a problem in your situation, or it might. Anyway it's good practice to never re-purpose an ID.
>
> MySQL started as a non-ACID query server (not a full relational database in the accepted sense) and these kinds of issues likely stem from that history. Folks getting started with databases and django may want to consider using Postgres for their foundation.

Actually, auto_increment has nothing to do with ACID. MySQL just chooses to not store the nextval across reboots. You can set it manually with "ALTER TABLE Foo AUTO_INCREMENT=123".

PostgreSQL creates a sequence as a separate single-row table to store the nextval so it is persistent across reboots, but you have to explicitly set the nextval if you e.g. bulk loading data into tables, which bypasses the sequence. If you don't, inserts may fail because the sequence is creating duplicate keys.

MySQL goes the usual not-always-helpful route of guessing what you want (February 31st, anyone?). PostgreSQL has more control at the expense of foot-shooting.

Erik

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/166D1AF3-64B9-4360-8BE6-7BA98158F984%40cederstrand.dk.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment