TypeError:'class Meta' 属性无效:Django4.2 中的 manager_inheritance_from_future

问题描述 投票:0回答:1

运行 makemiragtions 命令时出现上述错误。因此,我删除/重命名了现有的迁移文件夹并重新运行 makemirations 命令,它已被迁移,但是当我运行迁移时,我得到了相同的错误,即 TypeError: 'class Meta' gets invalid attribute(s): manager_inheritance_from_future。 这是我的模型课。

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

from django.conf import settings
from django.db import models


class CountryList(models.Model):

    CHOICES =[(1, 'Active'), (0, 'Inactive')]

    id = models.AutoField(primary_key=True, editable=False)
    name = models.CharField(max_length=255)
    iso3_code = models.CharField(max_length=5, verbose_name="ISO Code 3", help_text="ISO code with 3 leaters")
    iso2_code = models.CharField(max_length=5, verbose_name="ISO Code 2", help_text="ISO code with 2 leaters")    
    is_active = models.IntegerField(choices=CHOICES)

    def __str__(self) -> str:
        return self.name
    
    class Meta:
        managed = True
        db_table = 'Country_list'
        verbose_name = 'Country'
        verbose_name_plural = 'Countries'
        ordering = ['name','is_active']

注意:我从Django2.2迁移到Django4.2版本。

所以请让我知道任何对此有想法的人。 这是我的整个错误引用:

Operations to perform: Apply all migrations: admin, auth, careers, cms, contenttypes, emailsignup, fluent_contents, news, optionsquote, press, redirects, resource, retailfinder, sessions, sites Traceback (most recent call last): File "/Users/developemt/Documents/Repos/Djnago_axv/manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line utility.execute() File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/__init__.py", line 436, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 412, in run_from_argv self.execute(*args, **cmd_options) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 458, in execute output = self.handle(*args, **options) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/base.py", line 106, in wrapper res = handle_func(*args, **kwargs) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/core/management/commands/migrate.py", line 302, in handle pre_migrate_apps = pre_migrate_state.apps File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/utils/functional.py", line 57, in __get__ res = instance.__dict__[self.name] = self.func(instance) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/migrations/state.py", line 566, in apps return StateApps(self.real_apps, self.models) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/migrations/state.py", line 627, in __init__ self.render_multiple([*models.values(), *self.real_models]) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/migrations/state.py", line 665, in render_multiple model.render(self) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/migrations/state.py", line 956, in render return type(self.name, bases, body) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 143, in __new__ new_class.add_to_class("_meta", Options(meta, app_label)) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/models/base.py", line 371, in add_to_class value.contribute_to_class(cls, name) File "/Users/developemt/Documents/Repos/Djnago_axv/.venv/lib/python3.9/site-packages/django/db/models/options.py", line 232, in contribute_to_class raise TypeError( TypeError: 'class Meta' got invalid attribute(s): manager_inheritance_from_future 
我尝试过加起来

manager_interface_from_future = True or False

作为 Meta 类中的选项,我还注释掉了该类的整个 Meta 类,但没有用。 注意:我还有另一个带有 Meta calss 的模型类,具有相同的选项。

django django-models mysql-connector django-migrations python-3.9
1个回答
0
投票

manager_inheritance_from_future
在 django 1.11 中得到支持,他们在 django 2.2 中保留了这个 Meta 选项,以便向后兼容 Django 1.11,并且在 Django 4.2 中不再支持该选项。 所以我认为在你旧的迁移中的某些地方它在你的模型选项中设置了
manager_inheritance_from_future

抱歉。我想将其添加为评论,但 stackoverflow 不允许。

© www.soinside.com 2019 - 2024. All rights reserved.