gpt4 book ai didi

Django - 更改验证器名称会导致迁移回溯

转载 作者:行者123 更新时间:2023-12-03 09:34:26 25 4
gpt4 key购买 nike

我将 Django 1.9.2 与 python 3.4.2 一起使用。

在开发生命周期的前半部分,我有以下代码:

class ModificationOrder(ERN):
...
san_amount = models.IntegerField(default=0, \
validators=[validate_modificationorder_san_amount])

,并且我创建了一个初始迁移,导致 中的这一行0001_initial.py 文件:
migrations.CreateModel(
...
fields = [
...
('san_amount', models.IntegerField(default=0, validators=[shop.validators.validate_modificationorder_san_amount])),
])

.后来我进行了几次迁移,并删除了 san_amount 模型中的字段,但这可能与我的问题无关。

现在我尝试将验证器的名称更改为 validate_resource_san_amount ,但在更改 runserver 后会导致此错误:
python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f8ec1a5a510>
Traceback (most recent call last):
File "/home/csa.virtualenvs/sccdb34/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check_migrations()
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 163, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/db/migrations/loader.py", line 170, in build_graph
self.load_disk()
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/site-packages/django/db/migrations/loader.py", line 105, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/home/csa/.virtualenvs/sccdb34/lib/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/csa/git/sccdb/sccdb/shop/migrations/0001_initial.py", line 12, in <module>
class Migration(migrations.Migration):
File "/home/csa/git/sccdb/sccdb/shop/migrations/0001_initial.py", line 226, in Migration
('san_amount', models.IntegerField(default=0, validators=[shop.validators.validate_modificationorder_san_amount])),
AttributeError: 'module' object has no attribute 'validate_modificationorder_san_amount'

.

为了解决这个问题,我想将所有 validate_modificationorder_san_amount 更改为 validate_resource_san_amount 就足够了,但我想从概念上讲这是个坏主意。我应该如何以正确的方式处理这个问题? - 所以要更改已经在迁移文件中的验证器名称。

最佳答案

手动编辑迁移文件对我有用。只需转到错误中提到的迁移文件并删除验证器部分。

关于Django - 更改验证器名称会导致迁移回溯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41097198/

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