Django or similar for composite primary keys

后端 未结 4 1015
情话喂你
情话喂你 2020-12-14 10:47

I am writing a web application for my engineering company (warning: I am a programmer only by hobby) and was planning on using Django until I hit this snag. The models I wan

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-14 11:26

    I strongly suggest using a surrogate key. Not because it is "Djangoesque". Suppose that you use a composite key that includes part_number. What if some time later your company decides to change the format (and therefore values) of that field? Or in general terms, any field? You would not want to deal with changing primary keys. I don't know whatever benefit you see in using a composite key that consists of "real" values, but I reckon it isn't worth the hassle. Use meaningless, autoincremented keys (and that should probably render a composite key useless).

提交回复
热议问题