已解决:索引元 django

没有元 django 索引。

-admin

I am trying to add an index to my Django model. I have tried using the <code>db_index=True</code> and <code>index_together</code> fields, but they don't seem to work. I have also tried using the <code>Meta</code> class, but it doesn't seem to work either. 
<blockquote>
<p><strong><em><a href="https://docs.djangoproject.com/en/dev/ref/models/options/#indexes" rel="nofollow noreferrer">https://docs.djangoproject.com/en/dev/ref/models/options/#indexes</a></em></strong></p>
<p><strong><em><a href="https://docs.djangoproject.com/en/dev/ref/models/" rel="nofollow noreferrer">https://docs.djangoproject.com/en/dev//ref//models//options/#db-indexes</a></em></strong></p>
<p><strong><em><a href="https://stackoverflow.com/?q=add+an+index+in+Django">add an index in Django</a></em></strong></p>
<p><strong><em>(and many more)</em></strong>. </p>
</blockquote>

上面的代码试图向 Django 模型添加索引。 这 db_index=Trueindex_together 正在使用字段,但它们似乎不起作用。 这 Meta 类也在使用,但它似乎也没有用。

型号指标参考

模型索引引用是模型中的一个字段,用于存储模型实例的唯一标识符。 Django 使用该字段在访问数据库时唯一标识模型实例。

模型元选项

您可以在 Django 中使用一些元选项来控制模型的行为方式。

最常见的元选项是模型的 default_field,它指定在创建新对象时应将数据库中的哪个字段用作模型的默认值。 如果您想要为没有任何显式值的字段指定默认值,或者如果您想要为数据库自动填充的字段指定默认值,这将很有用。

另一个元选项是序列化器,它指定将对象保存到数据库时应使用哪个序列化器。 如果您想使用不同于 Django 自动提供的序列化程序,这会很有用。

相关文章:

发表评论