On Mon, 2009-02-02 at 23:16 -0500, alexander lind wrote: > > On Feb 2, 2009, at 10:05 PM, Malcolm Tredinnick wrote: > > > I always make my auto-inc fields primary as well, so no argument > > > there. > > > I tried using the AutoField when I noticed django didn't create > > > the > > > auto-incrementing fields correctly by itself in sqlite, but that > > > didn't work either until I patched it. > > > > Then something else is going on and maybe SQLite doesn't need the > > AUTOINCREMENT marker for some reason. Because automatic primary key > > fields work fine with SQLite. If that ever broke, we'd hear about it > > very quickly. > > > According to sqlite themselves, you can create a primary key without > using the AUTOINCREMENT marker, and this key will _almost_ act as an > autoinc field, but there is one important difference, and that is that > without the use of AUTOINCREMENT, sqlite does not guarantee that a new > ID is created for each insert. If you for example deleted the latest > row in the table, sqlite would re-use the ID of the deleted row for > the next insert. This is because without AUTOINCREMENT, the primary > key becomes an alias for sqlite:s internal ROWID, that works this way.
Okay, that sounds like the behaviour we need. So I'm comfortable that there isn't a major bug in Django now. [...] > I think django should use the AUTOINCREMENT marker on the AutoField > myself, makes sense to me. It's possible, but not a requirement. Since the documentation recommends what we're doing now, our current choice seems like a good idea, too. In the absence of any concrete bug and a real use-case that requires a change, I'd be unenthusiastic about changing current behaviour. > Still, sqlite does not behave as documented above for me. If I try to > use just the ROWID as primary key, I end up not being able to insert > any new rows because it will just tell me that the primary key may not > be null (when leaving the field out of the insert query, like you > would an auto-inc field). So you're trying to do something a bit weird then, since at least a few thousand people use SQLite in Django applications all the time without problems. I still don't really understand what it is you're trying to do, but I've decided I'm not particularly worried by it. Auto-generated primary keys in SQLite work fine. You can happily create and save models with them. If you want to manually declare the primary key field, go for it. You can even use AutoField and it will work fine with Django. If you want a field with different behaviour from AutoField, that's also fine, since it's easy to create custom fields for custom database types -- we've put a lot of effort into making that possible. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---