gpt4 book ai didi

Django 自定义 Auth 用户模型和重置迁移

转载 作者:行者123 更新时间:2023-12-01 13:43:37 24 4
gpt4 key购买 nike

我正在尝试在我的设置中设置自定义 AUTH_USER_MODEL,但由于过去的一些迁移,它抛出了一个 CircularDependencyError。 (我之前用的是普通用户)

我该如何解决这个问题?我不关心数据库,它只是一个测试对象。但是我可以重置/删除迁移还是需要开始一个全新的项目?

最佳答案

Django 警告不要更改 AUTH_USER_MODEL in the docs :

Changing AUTH_USER_MODEL has a big effect on your database structure. It changes the tables that are available, and it will affect the construction of foreign keys and many-to-many relationships. If you intend to set AUTH_USER_MODEL, you should set it before creating any migrations or running manage.py migrate for the first time.

Changing this setting after you have tables created is not supported by makemigrations and will result in you having to manually fix your schema, port your data from the old user table, and possibly manually reapply some migrations.

如果您不关心数据库,那么我会尝试删除数据库,删除您现有的迁移文件并再次运行 makemigrations

关于Django 自定义 Auth 用户模型和重置迁移,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37678634/

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