gpt4 book ai didi

python - django.core.exceptions.FieldError : Unknown field(s)

转载 作者:太空宇宙 更新时间:2023-11-03 21:46:56 31 4
gpt4 key购买 nike

我正在获取

django.core.exceptions.FieldError: Unknown field(s) (authorized_users_read_or_write, authorized_users_to_write, authorized_users_to_read) specified for FileUpload

更改模型中 3 个字段的名称后运行 makemigrations 时。我希望 Django 能够接受名称更改并根据更改进行迁移。型号为:

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models
from django.contrib.auth.models import User

class FileUpload(models.Model):
name = models.CharField(max_length=255, default='')
file = models.FileField(upload_to='uploads/%Y/%m/%d/')
upload_time = models.DateTimeField(auto_now_add=True, blank=True)
owner = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='files_owned')
description = models.TextField(null=True, blank=True)
users_authorized_to_read = models.ManyToManyField(User, related_name='file_read_permissions', null=True, blank=True)
users_authorized_to_write = models.ManyToManyField(User, related_name='file_write_permissions', null=True, blank=True)
users_authorized_to_read_or_write = models.ManyToManyField(User, related_name='file_read_write_permissions', null=True, blank=True)

def __str__(self):
return self.name

我更改了底部 3 个字段,这就是我更改的全部内容。

$ python3 manage.py makemigrations
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 350, in execute
self.check()
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 40, in check_url_namespaces_unique
all_namespaces = _load_all_namespaces(resolver)
File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
url_patterns = getattr(resolver, 'url_patterns', [])
File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/cchilders/projects/secure_code_warrior_django_project/secure_code_warrior_django_project/urls.py", line 24, in <module>
url(r'file-manager/', include('file_management.urls')),
File "/usr/local/lib/python3.5/dist-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/home/cchilders/projects/secure_code_warrior_django_project/file_management/urls.py", line 3, in <module>
from . import views
File "/home/cchilders/projects/secure_code_warrior_django_project/file_management/views.py", line 9, in <module>
from .forms import FileUploadForm
File "/home/cchilders/projects/secure_code_warrior_django_project/file_management/forms.py", line 26, in <module>
class FileUploadForm(ModelForm):
File "/usr/local/lib/python3.5/dist-packages/django/forms/models.py", line 266, in __new__
raise FieldError(message)
django.core.exceptions.FieldError: Unknown field(s) (authorized_users_read_or_write, authorized_users_to_write, authorized_users_to_read) specified for FileUpload

最佳答案

可能导致此错误的一个问题是在 ModelForm 中使用旧的字段名称,我就是这么做的

关于python - django.core.exceptions.FieldError : Unknown field(s),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52430656/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com