mysql - 在 Django 1.7 中从 auth_user 切换到 CustomUser

标签 mysql django python-2.7 django-models

我一直在使用 auth.User 用户模型。现在我将用户模型更改为custom.CustomUser。在使用auth.User的过程中制作了各种模型。因此,我的 mysql 数据库中的每个表都创建了列名 user_id 或具有带有“auth_user”的外键约束。因此出现了很多问题。除此之外的一切都工作正常。 AUTH_USER_MODEL 指向我的“custom.CustomUser”表,每个新用户都存储在 CustomUser 中。有没有办法将现有表的引用从 auth_user 更改为 custom_customuser。我使用的是 Django 1.7,它不支持南(据我所知)。

最佳答案

正如您提到的,您需要更新模型以指向settings.AUTH_USER_MODEL。这是一个例子:

your_field = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='yourmodel_yourfield')

然后,您需要使用 Django 的内部迁移。 South 的作者 Andrew Godwin 现在是 Django 的核心贡献者,因此使用 South 的任何人都应该相当熟悉它们:

文档:https://docs.djangoproject.com/en/1.8/topics/migrations/

如果您要升级到 1.7,那么也值得跳转到 1.8。您需要修改 TEMPLATE 设置和 urls.py 模式。 1.8 是一个长期 Django 版本。祝你好运!

关于mysql - 在 Django 1.7 中从 auth_user 切换到 CustomUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31293404/

相关文章:

php - 从表中选择组合字段

python - 将UTC时间字符串转换为日期时间对象

mysql - 当我使用month()填充数据时,mysql是否有fill函数()?

MySQL:变量 'general_log_file' 无法设置为 '~/path/to/new/file' 的值

python - 使用 Coffin 设置 Dajaxice 时出现未知标签 'dajaxice_js_import'

python - 在库 libxml2 中找不到函数 xmlCheckVersion。是否安装了 libxml2?错误 : command 'gcc' failed with exit status 1

python - Celery定时任务eta(apply_async(eta=xxx :23) option is not working

python - cx_Oracle.DatabaseError : DPI-1047: 64-bit Oracle Client library cannot be loaded: "dlopen(libclntsh.dylib, 1): image not found"

python - 使用 update() 向字典添加值

PHP MySQL 日期大于