On Tue, Aug 24, 2010 at 5:55 AM, Dan <danielklaffenb...@gmail.com> wrote:

> I have some troubles with my Django model: whenever I create a new
> object the ID (primary key) is not being assigned to it after calling
> obj.save().
>
> I am on RHEL with Python 2.4.3 and Django 1.2.1 (with MySQL backend).
>
> I've uploaded a code snippet which clearly shows the problem:
> http://pastebin.com/qtRgZVQY
>
> For the reference, this is the model I am using:
> class Attribute(models.Model):
>    id = models.PositiveIntegerField( db_column='attribute_id',
> primary_key=True )
>    name = models.CharField(max_length=255,
> db_column='attribute_name', unique=True)
>    _touchDate =
> models.DateTimeField( db_column='attribute_touchDate', editable=False,
> auto_now=True)
>    _touchUser = models.CharField(max_length=255,
> db_column='attribute_touchUser', editable=False, default='Unknown')
>
>    class Meta:
>        db_table = 'attribute'
>        app_label = 'lib'
>        ordering = ( 'name', )
>
>    def __unicode__(self):
>        return self.name
>
> Could anybody point me into some directions in order to solve the
> problem?
>

You've explicitly defined the primary key field as a positive integer field.
Marking it primary_key=True does not make it an auto-assigned
auto-incrementing field. If you want automatic assignment, you need to make
it an AutoField with primary_key=True.

Karen
-- 
http://tracey.org/kmt/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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