16👍
✅
From your migration file it’s normal that you get this error, you are trying to store a datetime on a Foreignkey which need to be an int.
This is happened when the migration asked you which value will be set for old Choice rows because the new ForeignKey is required.
To resolve it, you can change the migration file and change the datetime.date… to a valid id from the Question table like the code bellow. Or delete the migration file and re-run ./manage.py makemigrations, when you will be asked about the default value prompt a valid Question id, not a datetime.
from future import unicode_literals
from django.db import models, migrations
import datetime
class Migration(migrations.Migration):
dependencies = [ ('App11', '0003_remove_choice_question'), ]
operations = [
migrations.AddField(
model_name='choice',
name='question',
field=models.ForeignKey(default=1, to='App11.Question'), preserve_default=False, ),
]
2👍
pub_date
should not be a string. Create your object as follows:
from django.utils import timezone
Question.objects.create(ques_text="How are you?",pub_date=timezone.now())
- 'WSGIRequest' object has no attribute 'Post'
- Model class doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS
- Django REST Framework – multiple models / APIs?
Source:stackexchange.com