#8799: .save() and .objects.create() does not set the primary key when the model
has an explicit primary key field
---------------------------------+------------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: nobody
Status: new | Milestone:
Component: Database wrapper | Version:
Keywords: | Stage: Unreviewed
Has_patch: 0 |
---------------------------------+------------------------------------------
Here is what I observed on django1.0-beta2 and 0.96 releases with MySQL or
Sqlite3.[[BR]]
I have the following table:[[BR]]
Sqlite:
{{{
CREATE TABLE "Person" (
"id" integer NOT NULL PRIMARY KEY,
"name" text NOT NULL
)
MySQL:
CREATE TABLE `Person` (
`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,
`name` longtext NOT NULL
)
}}}
In the models.py I have
{{{
class Person(models.Model):
id = models.IntegerField(primary_key=True)
name = models.TextField()
class Meta:
db_table = u'Person'
}}}
When I issue:
{{{
p = Person.objects.create(name='Bob')
p.id
}}}
I get nothing. The record however is persisted.
Same happens with
{{{
p = Person('name'=Bob)
p.save()
p.id
}}}
If however the model is missing the id field and django auto generates it:
{{{
class Person(models.Model):
name = models.TextField()
class Meta:
db_table = u'Person'
}}}
Than everything is OK. The id is set correctly.
--
Ticket URL: <http://code.djangoproject.com/ticket/8799>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---