Django:创建灯具而不指定主键?(Django: Create fixtures without specifying a primary key?)

编程入门 行业动态 更新时间:2024-10-28 07:23:37
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.

更多推荐

本文发布于:2023-07-31 15:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1345274.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不   灯具   主键   Django   key

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!