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

查看:240
本文介绍了Django:创建灯具而不指定主键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关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,并且当对象被保存时,将分配主键。

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.

至少对于YAML来说,这是有用的,如果你手工制作,我猜你正在使用它。

This works for YAML at least, I'm guessing you're using that if you are creating by hand.

这篇关于Django:创建灯具而不指定主键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆