我有一个名为用户的模型,还有一个称为患者的模型,如下所示:
class Patient(Model):
user = OneToOneField('users.User', on_delete=CASCADE, related_name="patient",
blank=True, null=True)
class User(Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
所有迁移都可以正常工作,现在我正尝试使用固定装置向数据库添加一些数据。用户固定装置工作良好,但似乎患者固定装置无法检测到用户的UUID:
django.db.utils.IntegrityError: Problem installing fixtures: insert or update on table "patients_patient" violates foreign key constraint "patients_patient_user_id_b53513b7_fk_users_user_id"
DETAIL: Key (user_id)=(97179680-7042-11ea-bc55-0242ac130003) is not present in table "users_user".
这是我的灯具的外观:
[{
"model": "patients.patient",
"id": 1,
"fields": {
"user": "97179680-7042-11ea-bc55-0242ac130003"
}
},
]
[
{
"model": "users.User",
"id": "97179680-7042-11ea-bc55-0242ac130003",
}
},
]
我该如何解决?
好的,找到解决方案!而不是id
仅仅使用pk
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句