gpt4 book ai didi

python - makemigrations 无法识别数据库更改

转载 作者:行者123 更新时间:2023-11-30 23:02:38 26 4
gpt4 key购买 nike

我正在使用django,现在我将python文件从custom_fields重命名为fields并更改模型类和模型类正在使用来自 fields 文件的字段,但是当我运行

python manage.py makemigrations

存在这样的错误:

Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
utility.execute()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/__init__.py", line 342, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/core/management/commands/makemigrations.py", line 65, in handle
loader = MigrationLoader(None, ignore_no_migrations=True)
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 170, in build_graph
self.load_disk()
File "/Users/smy/wuque/projects/LinuxChat/Server/lib/python2.7/site-packages/django/db/migrations/loader.py", line 105, in load_disk
migration_module = import_module("%s.%s" % (module_name, migration_name))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/Users/smy/wuque/projects/LinuxChat/Server/LinuxChatServer/Server/migrations/0005_auto_20151215_1223.py", line 5, in <module>
import Server.custom_fields
ImportError: No module named custom_fields

我不知道如何解决这个错误,所以我尝试删除 migrates 文件夹,但是当我再次运行上面的命令时,没有检测到任何更改,即使我再次修改模型类。只需显示:

No changes detected.

现在我无法修改数据库表,谁能告诉我如何解决这个问题?谢谢!

最佳答案

makemigrations 用于应用将直接影响数据库底层结构的更改。

重命名你的Python文件不会对数据库产生任何影响,因为字段的类型没有改变,因此不会对数据库产生任何影响。您最终看到的只是 python 文件中的不同导入。

关于python - makemigrations 无法识别数据库更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34410963/

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