已解決:索引元 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 自動提供的序列化程序,這會很有用。

相關文章:

發表評論