小编Jag*_*gat的帖子

TypeError:int()参数必须是字符串或数字,而不是'datetime.datetime'

我将App12/models.py模块设为:

from django.db import models

class Question(models.Model):

    ques_text=models.CharField(max_length=300)
    pub_date=models.DateTimeField('Published date')

    def __str__(self):
        return self.ques_text

class Choice(models.Model):

    # question=models.ForeignKey(Question)
    choice_text=models.CharField(max_length=300)
    votes=models.IntegerField(default=0)

    def __str__(self):
        return self.choice_text
Run Code Online (Sandbox Code Playgroud)

然后我运行cmds

 python manage.py makemigrations App12
 python manage.py migrate
Run Code Online (Sandbox Code Playgroud)

然后在问题模型中输入2条记录:

Question.objects.create(ques_text="How are you?",pub_date='timezone.now()') 
                 # and (ques_text="What are you doing?",pub_date='timezone.now()')
Run Code Online (Sandbox Code Playgroud)

然后我意识到问题和选择模型应该是外键关系,并在模型代码中取消注释上面注释的语句

当我运行" python manage.py makemigrations App12"时,它运行良好,但在那之后,我得到了

"TypeError: int() argument must be a string or a number, not 'datetime.datetime"
Run Code Online (Sandbox Code Playgroud)

我正在运行"python manage.py migrate"命令时出错.

任何人都可以帮助我.如何在Choice模型和问题模型之间添加外键关系.

python django django-orm

11
推荐指数
1
解决办法
2万
查看次数

标签 统计

django ×1

django-orm ×1

python ×1