I have following django model
class CalculatedResults(models.Model):
id = models.IntegerField(primary_key=True)
tmstamp = models.DateTimeField()
latitude = models.FloatField()
longitude = models.FloatField()
magnitude = models.FloatField()
origin_time = models.DateTimeField()
actioncode = models.IntegerField(db_column='actionCode', blank=True, null=True) # Field name made lowercase.
class Meta:
managed = False
db_table = 'calculated_results'
verbose_name = 'Calculated Result'
verbose_name_plural = 'Calculated Results'
and relevant mysql table is :
CREATE TABLE IF NOT EXISTS `calculated_results` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`tmstamp` timestamp(5) NOT NULL DEFAULT CURRENT_TIMESTAMP,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`magnitude` double NOT NULL DEFAULT '0',
`origin_time` timestamp(5) NOT NULL DEFAULT '0000-00-00 00:00:00.00000',
`actionCode` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `tmstamp_index` (`tmstamp`),
KEY `origin_time_index` (`origin_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=814 ;
When I try to retrieve data from the table using python manage.py shell
using following code,
form eew_main.models import CalculatedResults
a = CalculatedResults.objects.all().order_by('-id')[:1]
I get None
for tmstamp
and origin_time
but as far as I have investigated the issue, following sql query is sent to mysql
SELECT `calculated_results`.`id` , `calculated_results`.`tmstamp` , `calculated_results`.`latitude` , `calculated_results`.`longitude` , `calculated_results`.`magnitude` , `calculated_results`.`origin_time` , `calculated_results`.`actionCode`
FROM `calculated_results`
ORDER BY `calculated_results`.`id` DESC
LIMIT 1
When I try it on mysql with same mysql user that django uses I got all the values.
So please help me to somehow find a way to investigate and resolve this issue.
Thanks!