Reputation: 380
With django version 1.10.3 I am creating the mysql table
MariaDB [ipp_database]> SELECT * FROM polls_question;
+----+----------------+----------------------------+
| id | question_text | pub_date |
+----+----------------+----------------------------+
| 1 | What's up? | 2016-10-06 11:04:36.703335 |
| 2 | Klappt das so? | 2016-11-24 09:39:11.953693 |
| 3 | Klappt das so? | 2016-11-24 09:40:08.260329 |
| 4 | Klappt das so? | 2016-11-24 10:32:54.000000 |
| 5 | Klappt das so? | 2016-11-24 10:32:57.000000 |
+----+----------------+----------------------------+
5 rows in set (0.00 sec)
with the model
from __future__ import unicode_literals
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
def __str__(self):
return self.choice_text
and the Command
from django.core.management.base import BaseCommand
from polls.models import Question
from django.utils import timezone
class Command(BaseCommand):
def handle(self, *args, **kwargs):
q = Question(question_text="Klappt das so?", pub_date=timezone.now())
q.save()
for question in Question.objects.order_by('id'):
print u"%s %s %s" % (question.id, question.question_text, question.pub_date)
In the mysql terminal it is showing correctly but when reading with the command posted it gives
1 What's up? None
2 Klappt das so? None
3 Klappt das so? None
4 Klappt das so? None
5 Klappt das so? None
Any idea, why the "pub_date" column reads None? Thank you, Daniel
Upvotes: 1
Views: 58
Reputation: 20349
This is a known issue https://code.djangoproject.com/ticket/19716
ALTER TABLE polls_question MODIFY COLUMN pub_date datetime NOT NULL
Upvotes: 3