unique-constraint

Django UniqueConstraint

╄→гoц情女王★ 提交于 2020-08-04 11:13:29
问题 Context I have the models AppVersion , App & DeployApp . In the AppVersion model users can upload APK files to the filesystem. I am using a pre_save signal to prevent uploading APK files with the same version_code for a specific App like this: @receiver(pre_save, sender=AppVersion) def prevent_duplicate_version_code(sender, instance, **kwargs): qs = AppVersion.objects.filter(app_uuid=instance.app_uuid, version_code=instance.version_code) if qs.exists(): raise FileExistsError("Version code has

How to force EclipseLink's @PrivateOwned to perform delete before insert

懵懂的女人 提交于 2020-08-02 12:29:25
问题 I have an entity which has @OneToMany private ownership of a collection of another entities. That other entity has some unique constraints over different set of columns. The problem arises when I want to update the main entity (together with changed child entities). EclipseLink does insert before delete, so sometimes, an insertion violates the constraint and throws an exception. Is there a way to force the deletion of child entities before inserting their updated counterparts? 回答1: I know, I