i'm using a 3rd party mysql database and integrating with this table:
{{{
CREATE TABLE `alerts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`date` datetime NOT NULL,
`message` text NOT NULL,
`severity` int(11) NOT NULL,
`state` int(11) NOT NULL,
`title` varchar(255) NOT NULL,
`type` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=943271 DEFAULT CHARSET=latin1;
}}}
iv'e used inspect db to generate this model:
{{{
class Alerts(models.Model):
id = models.IntegerField(primary_key=True)
date = models.DateTimeField()
message = models.CharField(max_length=255)
severity = models.IntegerField()
state = models.IntegerField()
title = models.CharField(max_length=255)
type = models.IntegerField()
class Meta:
managed = False
db_table = 'alerts'
}}}
this is the snippet i'm using to create a new {{{alert}}} entity:
{{{
alert_entity = Alerts()
alert_entity.date = alert['date']
alert_entity.message = alert['message']
alert_entity.title = alert['title']
alert_entity.severity = alert['severity']
alert_entity.state = alert['state']
alert_entity.type = alert['type']
alert_entity.save()
}}}
after {{{.save()}}} i got {{{None}}} value in {{{.id}}} and in {{{.pk}}}
i tried things, and changing the model from
{{{
id = models.IntegerField(primary_key=True)
}}}
to:
{{{
id = models.AutoField(primary_key=True)
}}}
workaround my issue. (got the valid values of the new id in {{{.id}}} and
in {{{.pk}}})
BTW, i'm getting these warning when saving:
{{{
/usr/local/lib/python2.7/dist-
packages/django/db/models/fields/__init__.py:903: RuntimeWarning:
DateTimeField Tasks.end_date received a naive datetime (2014-06-18
22:15:13) while time zone support is active.
RuntimeWarning)
/usr/local/lib/python2.7/dist-
packages/django/db/models/fields/__init__.py:903: RuntimeWarning:
DateTimeField Tasks.start_date received a naive datetime (2014-06-18
22:05:13) while time zone support is active.
RuntimeWarning)
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/22884>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Comment:
Can you write a test for Django's test suite that reproduces the error?
The RuntimeWarnings is an issue with your code, see
https://docs.djangoproject.com/en/1.6/topics/i18n/timezones/#code.
--
Ticket URL: <https://code.djangoproject.com/ticket/22884#comment:1>
* status: new => closed
* resolution: => duplicate
Comment:
This is expected behavior, core backends introspection is currently based
on PEP 249's cursor.description, which doesn't allow us to introspect if
the field is autoincrement or not. After fixing #21907, the output will
now at least output a hint "# AutoField?" after the field to suggest the
field type change during review.
--
Ticket URL: <https://code.djangoproject.com/ticket/22884#comment:2>