On Sat, 2009-01-31 at 16:56 -0500, alexander lind wrote:
>  
> > > 
> > > class User(models.Model):
> > >  user_id = models.AutoField(primary_key=True)
> > > 
> > > This produces a table in sqlite that will NOT take NULL for a
> > > value  
> > > when inserting records. You get an error back.
> > 
> > That's correct behaviour. A primary key column must be unique and
> > not
> > null. By definition. No bug there.
> 
> 
> Right. I stated it because if you do an insert and just leave the
> autoincrementing field out of the field-list, sqlite will return the
> "sorry, null is not an acceptable value for this field". I was a bit
> unclear.
> 
> > 
> > That's not the right solution. You're making the symptom go away,
> > not
> > fixing the problem itself.
> > 
> > Your observation is correct: the SQLite backend doesn't add
> > AUTOINCREMENT. The fix is to make it always add AUTOINCREMENT. An
> > AutoField is an auto-increment field: it's not optional.
> 
> 
> You're right.
> 
> > 
> > 
> > Shows how infrequently AutoField's are really used in practice.
> > They're
> > generally just not that useful to specify.
> 
> 
> What else do people use for specifying autoinc fields?

Auto-increment fields generally aren't that useful in practice, outside
of primary keys (the reasonsing being that, since they can act as
primary keys, you might as well make it the table's primary key if
you're using one. A non-primary key auto-inc field is usually a sign of
an unnecessarily denormalised data model). Since Django automatically
creates an auto-increment primary key field, the majority of the time
the manual specification isn't needed.

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
-~----------~----~----~----~------~----~------~--~---

Reply via email to