Re: Object ID is not assigned after calling save() on a new object
Django assigns an id field to models automatically, so you dont need
to define it seperately. And even if you define it you have to assign
auto_increment = true so that it is automatically filled.
On Aug 24, 2:55 pm, Dan <danielklaffenb...@gmail.com> wrote:
> Hi,
>
> 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?
>
> Regards,
> Daniel
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home