Django:创建灯具而不指定主键?(Django: Create fixtures without specifying a primary key?)
有关Django灯具的错误之一就是您必须指定每个型号的主键。 有没有办法创建灯具,而不必为每一行指定一个主键?
One of the things that bugs me about Django fixtures is that you've got to specify every model's primary key. Is there any way to create fixtures without having to specify a primary key for each row?
最满意答案
使用“pk:null”而不是“pk:1”(或任何),这将导致PK被设置为None,并且当保存对象时,将分配主键。
至少对于YAML来说,这是有用的,如果你手工制作,我猜你正在使用它。
Use "pk: null" instead of "pk: 1" (or whatever), which will result in the PK being set to None, and when the object is saved a primary key will be assigned.
This works for YAML at least, I'm guessing you're using that if you are creating by hand.
更多推荐
发布评论