Den 27/01/2014 kl. 17.22 skrev Malik Rumi <malik.a.rumi@gmail.com>:
> I read this on the django project site:
> Since MySQL 5.5.5, the default storage engine is InnoDB. This engine is fully transactional and supports foreign key references. It's probably the best choice at this point. However, note that the the InnoDB autoincrement counter is lost on a MySQL restart because it does not remember the AUTO_INCREMENT value, instead recreating it as "max(id)+1". This may result in an inadvertent reuse of AutoField values.
> Now to my newby senses, this is a huge problem. How can you have a primary key, or a foreign key, without the assurance that they are unique?
"reuse" does not imply "non-unique" in this situation - MySQL will still make sure that the ID field is unique. It just means that an ID you have previously deleted from the table may be reused. Consider this:
1) The last user you added was assigned ID 122
2) You add user "John Doe", MySQL assigns the value 123 to the ID field
3) You delete record with ID 123 again
4) MySQL reboots, resetting AUTO_INCREMENT to 122+1=123
5) You add user "Jane Smith", MySQL assigns the value 123 to the ID field
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.
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/3E44BD85-D6E6-41B1-9980-C5BA99B0C136%40cederstrand.dk.
For more options, visit https://groups.google.com/groups/opt_out.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment