1

设想:

我在 Django 中使用simple_history包。

在文档中,在高级使用部分“第三方模型的历史”它说,

" 要跟踪您未创建的模型的历史记录,请使用 simple_history.register 实用程序。您可以使用它来跟踪您无法控制的第三方应用程序中的模型。这是使用 simple_history.register 记录历史记录的示例-从 django.contrib.auth 应用程序跟踪用户模型”

所以我把代码放在 models.py 中(也尝试了 admin.py),如下所示:

from simple_history import register
from django.contrib.auth.models import User

register(User)

问题:当我运行python manage.py makemigrations它给出以下错误:

E:! Project\CMIT\CMITv0101\cmit001>python manage.py makemigrations
Migrations for 'auth':
C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations\0009_historicaluser.py
- Create model HistoricalUser
Traceback (most recent call last):
File "manage.py", line 22, in
execute_from_command_line(sys.argv)
File "C:\Program Files\Python36\lib\site-packages\django\core\management_init_.py", line 363, in execute_from_command_line
utility.execute()
File "C:\Program Files\Python36\lib\site-packages\django\core\management_init_.py", line 355, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 283, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\base.py", line 330, in execute
output = self.handle(*args, **options)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\commands\makemigrations.py", line 193, in handle
self.write_migration_files(changes)
File "C:\Program Files\Python36\lib\site-packages\django\core\management\commands\makemigrations.py", line 232, in write_migration_files
with io.open(writer.path, "w", encoding='utf-8') as fh:
PermissionError: [Errno 13] Permission denied: 'C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations\0009_histo
ricaluser.py'

我现在可以做什么来注册我的用户模型?

4

1 回答 1

0

根据错误描述,您无权在文件夹 C:\Program Files\Python36\lib\site-packages\django\contrib\auth\migrations 中进行更改

更改文件夹的读取、写入和执行权限。完成后,运行python manage.py makemigrations

此外,您正在尝试在系统包中进行迁移。您可以在单独的应用程序中创建自定义用户模型,然后在那里进行迁移。

于 2018-04-17T19:49:45.373 回答