我正在使用django 1.7.11。我有一个预先存在的项目,我决定尝试使用内置的管理面板(我还没有创建超级用户)。当我打开auth页面时,我看到了:
认为表格可能有问题我决定删除sqlite数据库并重新运行所有内容:
$ python manage.py makemigrations app1
Migrations for 'app1':
0001_initial.py:
- Create model Seller
$ python manage.py migrate
Operations to perform:
Synchronize unmigrated apps: crispy_forms
Apply all migrations: admin, contenttypes, auth, app1, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying app1.0001_initial... FAKED
$ python manage.py syncdb
Operations to perform:
Synchronize unmigrated apps: crispy_forms
Apply all migrations: admin, contenttypes, auth, app1, sessions
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
No migrations to apply.
You have installed Django's auth system, and don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Created:
Error: '' value has an invalid format. It must be in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format.
Created:
我该如何解决这个问题?
编辑:
APP1 / models.py:
from django.db import models
# from django.contrib.auth.models import AbstractUser
class Seller(models.Model):
# Address
contact_name = models.CharField(max_length=50)
contact_address = models.CharField(max_length=50)
contact_email = models.CharField(max_length=50)
contact_phone = models.CharField(max_length=50)
............
created = models.DateTimeField(auto_now_add=True,unique=True)
REQUIRED_FIELDS = ('contact_name','contact_email','contact_address','contact_phone')
USERNAME_FIELD = 'created'
答案 0 :(得分:1)
您的username
字段设置为created
。将其更改为contact_name以使用" name"登录。
但是!...您应该扩展AbstractUser模型,除非您真的需要,否则不要更改USERNAME_FIELD。您现在的方式是要求您编写自定义登录视图等。
编辑:
要使用默认用户模型,只需从settings.py中删除AUTH_USER_MODEL行,然后重新运行createsupseruser管理命令。然后返回管理员登录页面并使用用户名和密码登录。