【问题标题】:django auth system 'created'django 身份验证系统“已创建”
【发布时间】:2016-08-08 14:40:16
【问题描述】:

我正在使用 django 1.7.11。我有一个预先存在的项目,我决定尝试使用内置的管理面板(我还没有创建超级用户)。当我打开身份验证页面时,我看到了:

考虑到表可能有问题我决定删除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'

【问题讨论】:

  • 你能在 app1 中发布你的 models.py 吗? AUTH_USER_MODEL 未指向您发布的屏幕截图中的实际模型。您是否打算使用自定义用户模型?

标签: python django


【解决方案1】:

您的username 字段设置为created。将其更改为 contact_name 以使用“名称”登录。

但是!...您可能应该扩展 AbstractUser 模型,而不是更改 USERNAME_FIELD,除非您真的必须这样做。您现在的操作方式将要求您编写自定义登录视图等。

编辑:

要使用默认用户模型,只需从 settings.py 中删除 AUTH_USER_MODEL 行,然后重新运行 createupuseruser 管理命令。然后回到管理员登录页面,使用用户名和密码登录。

【讨论】:

  • nkhumphreys ,感谢您查看此内容。我真正需要的是允许我使用管理面板的超级用户。我宁愿有一个与用户模型分开的卖家模型。在这种情况下,我需要做什么来制作最基本的用户模型类?
  • 谢谢,删除该行后,我最终删除了迁移文件夹和 sqllite db,然后运行 ​​makemigrations app1,然后迁移 syncdb,我能够创建一个 SU。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-18
  • 1970-01-01
  • 2012-12-09
  • 1970-01-01
相关资源
最近更新 更多