django-user-accounts:没有这样的表:account_passwordhistory

时间:2018-10-23 12:35:55

标签: django authentication account

有许多与django相关的帖子,显示“无此表”错误,但没有任何一个来自django-user-accounts模块。 我收到此错误

  

sqlite3.OperationalError:没有这样的表:account_passwordhistory

,步骤如下:

已安装的django用户帐户:

$ pip install django-user-accounts
Collecting django-user-accounts
  Downloading https://files.pythonhosted.org/packages/0c/4f/40f76395324d98b7f8717aad7e08ad6f86ba2714eb956be6070e0402988c/django_user_accounts-2.0.3-py2.py3-none-any.whl (106kB)
    100% |████████████████████████████████| 112kB 2.8MB/s
.
.
.
Installing collected packages: django-appconf, django-user-accounts
Successfully installed django-appconf-1.0.2 django-user-accounts-2.0.3

在settings.py中添加了

INSTALLED_APPS = [ . . .
    'django.contrib.sites',
    'account' ]

SITE_ID = 1

MIDDLEWARE = [
.
.
.
    'account.middleware.ExpiredPasswordMiddleware',
]

ACCOUNT_PASSWORD_USE_HISTORY = True
ACCOUNT_PASSWORD_EXPIRY = 60  # number of seconds

重新启动服务器并运行:$ python manage.py user_password_history

我知道了

Traceback (most recent call last): 
File "/Users/ipozdnya/miniconda3/lib/python3.5/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params) 
File "/Users/someuser/miniconda3/lib/python3.5/site-packages/django/db/backends/sqlite3/base.py", line 328, in execute return Database.Cursor.execute(self, query, params) 
sqlite3.OperationalError: no such table: account_passwordhistory

我意识到在安装或其他步骤时没有创建account_passwordhistory。 $ python manage.py makemigrations指出No changes detected。该文档中没有任何内容告诉我该怎么做:http://blog.pinaxproject.com/2016/11/22/how-configure-password-expiration-for-your-site/

谢谢

1 个答案:

答案 0 :(得分:0)

好的,我的问题是我信任$ python manage.py makemigrations的输出 表示No changes detected。但是,当我运行$ python manage.py migration时,它对account_passwordhistory和account_passwordexpire表应用了新的迁移:

Applying account.0003_passwordexpiry_passwordhistory... OK

这些表在数据库中。

将我的密码设置为在1秒后过期(python manage.py user_password_expiry my_user_name --expire 1)对站点功能没有任何影响,但这是另一个问题。