On Fri, 2009-01-30 at 22:37 -0500, alexander lind wrote:
> I am using the svn trunk version of Django.
> 
> I was just starting a new django project using sqlite for the db  
> backend. Excerpt from models.py:
> 
> 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.

>  Reading sqlites manual,  
> this is _supposed_ to work, but doesn't seem to. However and  
> furthermore, you don't really get autoincrement behavior from sqlite  
> unless you add in the SQL keyword "AUTOINCREMENT" when creating the  
> table.
> 
> Django does not do this currently, so I hacked in an option in  
> db.models, so I can now do:

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.

Shows how infrequently AutoField's are really used in practice. They're
generally just not that useful to specify.

Anyway, if you you'd like to fix your patch to always do this for the
SQLite backend, that would be great (it looks like a one-line patch to
django/db/backends/sqlite/creation.py).

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