使主键与Django中的2个字段? [英] make primary key with 2 fields in Django?
本文介绍了使主键与Django中的2个字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从Django中的2个字段创建主键。
I want to make a primary key from 2 fields in Django.
字段如下:
- current Time
- userId
Time + userid {PK } [ Current Time + userid]
谢谢!
推荐答案
Django使用代理键运行得最好 - 也就是说,它自动定义一个自动增量字段<$ p c $ c> id 并将其设置为主键。
Django operates best with surrogate keys - that is, it automatically defines an autoincrement field called id
and sets that to be the primary key. That suits for almost all uses.
如果您需要在两个或多个字段上对模型强制使用唯一约束,则可以使用 class
中设置 $ $
。
If you then need to enforce a unique constraint on your model across two or more fields, you can use the unique_together
setting in the inner Meta
class.
这篇关于使主键与Django中的2个字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文