python - 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'
解决方案
推荐阅读
- javascript - Vuejs 搜索过滤器
- pdf - Azure 计算机视觉 API - PDF 文件上的 OCR 到文本
- java - 处理两个对象(实体)之间的字段
- javascript - 从浏览器的 es6 模块中无法识别的 node_modules 导入
- android - 如何以编程方式将背景颜色从 android.support.design 更改为 MaterialButton
- osgi - 在 OSGI 容器中启动 Apache Ignite 时出错
- git - Jenkins - 当 Jenkins 构建失败时阻止合并按钮
- uml - 扩展用例的正确表示法
- java - 输入“Q”时如何使Java程序退出,问题是默认输入变量是double
- python - 如何解决最大递归深度错误