【发布时间】:2019-06-17 08:26:09
【问题描述】:
如何在 Django 模块中将用户名设置为 ForeignKey。 下面的方法对吗?
user = models.ForeignKey(User, db_column="user")
我不能使用 ID 作为 ForeignKey,因为我的旧数据库的用户名是 ForeignKey。(我需要迁移旧数据)
【问题讨论】:
-
也许这个链接可以帮助...stackoverflow.com/questions/3641483/…
-
你确实应该迁移你的架构和数据,至少如果你重视你的数据......
-
@brunodesthuilliers 是这个正确的用户 = models.ForeignKey(User, on_delete=models.CASCADE, to_field="username")
-
@Kombuwa 你试过了吗?
标签: django django-models django-1.11