我正在尝试使用Django创建一个网站,下一步是运行manage.py以创建超级用户,但是当我输入用户名,电子邮件地址,密码,然后按Enter时,IDE(Pycharm)会反馈Commanderror:
manage.py@education > createsuperuser
"D:\PyCharm 2019.1\bin\runnerw64.exe" E:\pythonproject\education\Scripts\python.exe "D:\PyCharm 2019.1\helpers\pycharm\django_manage.py" createsuperuser E:/pythonproject/education
Tracking file by folder pattern: migrations
Username: admin
Email address: 976413993@qq.com
Warning: Password input may be echoed.
Password: 12345678
Warning: Password input may be echoed.
Password (again): 12345678
This password is too common.
This password is entirely numeric.
Bypass password validation and create user anyway? [y/N]: y
CommandError: '' value has an invalid date format. It must be in YYYY-MM-DD format.
这是UserProfile:
# -*- encoding:utf-8 -*-
from django.db import models
from django.contrib.auth.models import AbstractUser
from datetime import datetime
# Create your models here.
class UserProfile(AbstractUser):
nick_name = models.CharField(max_length=50, default="", verbose_name=u"昵称")
birday = models.DateField(verbose_name=u"生日", default="")
gender = models.CharField(choices=(("male", u"男"), ("female", u"女")), default="male", max_length=10)
address = models.CharField(max_length=100, default=u"")
mobile = models.CharField(max_length=11, null=True, blank=True)
image = models.ImageField(upload_to="image/%Y/%m", default=u"image/default.png", max_length=100)
class Meta:
verbose_name = "用户信息"
verbose_name_plural = verbose_name
def __unicode__(self):
return self.username
class EmailVerifyRecord(models.Model):
code = models.CharField(max_length=20, verbose_name=u"验证码")
email = models.EmailField(max_length=50, verbose_name=u"邮箱")
send_type = models.CharField(choices=(("register", u"注册"), ("forget", u"找回密码")), max_length=10)
send_time = models.DateTimeField(default=datetime.now)
class Meta:
verbose_name = u"邮箱验证码"
verbose_name_plural = verbose_name
class Banner(models.Model):
title = models.CharField(max_length=100, verbose_name=u"标题")
image = models.ImageField(upload_to="banner/%Y/%m", verbose_name=u"轮播图", max_length=100)
url = models.URLField(max_length=100, verbose_name=u"访问地址")
index = models.IntegerField(default=100, verbose_name=u"顺序")
add_time = models.DateTimeField(default=datetime.now, verbose_name=u"添加时间")
class Meta:
verbose_name = u"轮播图"
verbose_name_plural = verbose_name
我尝试通过Google搜索此问题,但找不到任何有用的信息。
答案 0 :(得分:1)
您不能将default=""
赋予DateField
,也不能将其更改为CharField
或
执行此操作
birday = models.DateField(verbose_name=u"生日", null=True)
更改后,请确保先运行makemigrations
和migrate
然后运行create superuser