【问题标题】:django-user-accounts : no such table: account_passwordhistorydjango-user-accounts:没有这样的表:account_passwordhistory
【发布时间】:2019-03-27 16:53:44
【问题描述】:

有很多与 django 相关的帖子带有“没有这样的表”错误,但没有一个来自 django-user-accounts 模块。 我收到此错误

sqlite3.OperationalError: no such table: account_passwordhistory

,步骤如下:

已安装 django-user-accounts:

$ 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/

谢谢

【问题讨论】:

    标签: django authentication account


    【解决方案1】:

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

    Applying account.0003_passwordexpiry_passwordhistory... OK
    

    这些表在数据库中。

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

    【讨论】:

    • makemigrations 对数据库没有任何作用。它检测models.py 中的更改,然后制作迁移文件。另一方面,migrate 会根据数据库检查所有迁移文件。如果数据库没有更新到最新的迁移,那么它将遵循迁移文件中的说明。我只是说你还没有对数据库做任何事情。这就是为什么没有这样的表错误。
    • 明白。我没有运行 migrate 因为我认为没有什么要迁移的(“未检测到更改”)。通常对于模型更改,我会看到我接触过的东西的列表。结果表明,makemigrations 不会像报告对模型所做的更改一样报告对 settings.py(在我的情况下为 INSTALLED_APPS)所做的更改。
    猜你喜欢
    • 1970-01-01
    • 2017-07-04
    • 2012-09-28
    • 2021-12-10
    • 1970-01-01
    • 2013-08-18
    • 2021-08-18
    • 2019-05-07
    相关资源
    最近更新 更多