Django heroku connect读写主键问题

Django heroku connect read-write primary key issue

我正在使用 djagno-heroku-connect 库、salesforce 和 heroku connect link 下面的库

https://github.com/Thermondo/django-heroku-connect


所以我面临的问题是我有一个模型被标记为读写,所以我应该将哪个字段作为主键,

I can't make sf_id as pk, because when i create one object it won't be there, as this is provided by salesforce

As suggested in docs create external_id, but this won't be present if data from salesforce is synced back to my database let's say postgres

There is one id field in postgres which is used by heroku connect and its suggested in docs on not to use that

而且我不愿意为此使用 salesforce API,有什么方法可以做到这一点吗?

提前致谢

嘿 Achintya Ranjan Chaudhary!

我叫 Rust,我是 django-heroku-connect 维护者之一。我很乐意在这里为您提供帮助。

你对 sf_id 字段的注释是完全正确的——这个不能用作主键,因为它的性质(它只会被 SF 填充,不可能有瞬间通过 Python/Django).

创建对象时的值

库中没有关于主键的严格要求,可以而且应该忽略显式定义,这意味着,Django 将自动设置类似于以下的默认主键字段:

id = models.AutoField(primary_key=True)

这样字段将映射到 Heroku Connect system field id。 这正是我们在 Thermondo 使用我们的库的方式,它完全没问题,但你必须确保你没有在你的代码中使用这个主键。 Heroku Connect 不保证对象的一致性和顺序,例如 table re-sync 操作将完全改变对象的 ids.

作为额外的建议,我建议使用 external_uuid UUID 字段,该字段将由 Django(在模型定义上设置默认值)和 Salesforce(这将需要自定义触发器)自动填充使用生成的 UUID 值填充 ExternalUUID__c 字段)。这将帮助您拥有一个唯一的 system-agnostic 参考 ID,可用于关系或其他 inter-communication 操作。

我希望这对您有所帮助,但请毫无疑问地提出有关此主题的任何其他问题!

最佳,
生锈