我可以在没有自动身份证的Django中创建模型吗? [英] Can I create model in Django without automatic ID?

查看:113
本文介绍了我可以在没有自动身份证的Django中创建模型吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个没有主键的表(在Django中它是自动创建的)。所以我的问题是:我可以创建一个没有ID /主键的模型吗?

I need a table without a primary key (in Django it was created automatically). So my question is: Can I create a model without an ID/primary key?

我正在使用Django 1.7。

I'm using Django 1.7.

推荐答案

您可以创建没有自动递增键的模型,但您不能创建一个没有主键。

You can create a model without an auto-incrementing key, but you cannot create one without a primary key.

Django文档


如果Django看到你已经明确设置 字段.primary_key ,它不会添加自动标识列。

If Django sees you’ve explicitly set Field.primary_key, it won’t add the automatic id column.

每个模型只需要一个字段来具有 primary_key = True (明确声明或自动添加)。

Each model requires exactly one field to have primary_key=True (either explicitly declared or automatically added).

这篇关于我可以在没有自动身份证的Django中创建模型吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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