首页 > 解决方案 > Django 迁移错误:TypeError:int() 参数必须是字符串、类似字节的对象或数字,而不是 'datetime.datetime'

问题描述

我试图为我的字段设置一个默认值,但它会导致错误。

文件:

模型.py

        from django.db import models
        from django.contrib.auth.models import User

        # Create your models here.
        STATUS = [
            (0, "Draft"),
            (1, "Publish")

        ]
        class Posts(models.Model):
            title = models.CharField(max_length=200, unique=True)
            slug = models.SlugField(max_length=200, unique=True)
            author = models.ForeignKey(User, on_delete= models.CASCADE,related_name='blog_posts')
            content = models.TextField()
            created_on = models.DateTimeField(db_index=True,auto_now=True)
            status = models.IntegerField(choices=STATUS, default=0)

我收到以下错误:

TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'

标签: pythondjangodjango-models

解决方案


推荐阅读