<legend id='k9LqF'><style id='k9LqF'><dir id='k9LqF'><q id='k9LqF'></q></dir></style></legend>

  1. <i id='k9LqF'><tr id='k9LqF'><dt id='k9LqF'><q id='k9LqF'><span id='k9LqF'><b id='k9LqF'><form id='k9LqF'><ins id='k9LqF'></ins><ul id='k9LqF'></ul><sub id='k9LqF'></sub></form><legend id='k9LqF'></legend><bdo id='k9LqF'><pre id='k9LqF'><center id='k9LqF'></center></pre></bdo></b><th id='k9LqF'></th></span></q></dt></tr></i><div id='k9LqF'><tfoot id='k9LqF'></tfoot><dl id='k9LqF'><fieldset id='k9LqF'></fieldset></dl></div>
    <tfoot id='k9LqF'></tfoot>
    • <bdo id='k9LqF'></bdo><ul id='k9LqF'></ul>

    <small id='k9LqF'></small><noframes id='k9LqF'>

      在 Django 模型中指定一个 mySQL ENUM

      Specifying a mySQL ENUM in a Django model(在 Django 模型中指定一个 mySQL ENUM)
      <legend id='frwMd'><style id='frwMd'><dir id='frwMd'><q id='frwMd'></q></dir></style></legend>
        <tbody id='frwMd'></tbody>

        <small id='frwMd'></small><noframes id='frwMd'>

            <tfoot id='frwMd'></tfoot>
            <i id='frwMd'><tr id='frwMd'><dt id='frwMd'><q id='frwMd'><span id='frwMd'><b id='frwMd'><form id='frwMd'><ins id='frwMd'></ins><ul id='frwMd'></ul><sub id='frwMd'></sub></form><legend id='frwMd'></legend><bdo id='frwMd'><pre id='frwMd'><center id='frwMd'></center></pre></bdo></b><th id='frwMd'></th></span></q></dt></tr></i><div id='frwMd'><tfoot id='frwMd'></tfoot><dl id='frwMd'><fieldset id='frwMd'></fieldset></dl></div>

              • <bdo id='frwMd'></bdo><ul id='frwMd'></ul>

                本文介绍了在 Django 模型中指定一个 mySQL ENUM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                如何在 Django 模型中指定和使用 ENUM?

                How do I go about specifying and using an ENUM in a Django model?

                推荐答案

                来自 Django 文档:

                MAYBECHOICE = (
                    ('y', 'Yes'),
                    ('n', 'No'),
                    ('u', 'Unknown'),
                )
                

                然后在模型中定义一个字符域:

                And you define a charfield in your model :

                married = models.CharField(max_length=1, choices=MAYBECHOICE)
                

                如果你不喜欢有字母,你可以对整数字段做同样的事情在您的数据库中.

                You can do the same with integer fields if you don't like to have letters in your db.

                在这种情况下,重写您的选择:

                In that case, rewrite your choices:

                MAYBECHOICE = (
                    (0, 'Yes'),
                    (1, 'No'),
                    (2, 'Unknown'),
                )
                

                这篇关于在 Django 模型中指定一个 mySQL ENUM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                How to update a record using sequelize for node?(如何使用节点的 sequelize 更新记录?)
                How to provide a mysql database connection in single file in nodejs(如何在 nodejs 中的单个文件中提供 mysql 数据库连接)
                Looping Over Result Sets in MySQL(在 MySQL 中循环结果集)
                Python : How to insert a dictionary to a sqlite database?(Python:如何将字典插入到 sqlite 数据库中?)
                Python and SQLite: insert into table(Python 和 SQLite:插入表)
                What is an efficient way of inserting thousands of records into an SQLite table using Django?(使用 Django 将数千条记录插入到 SQLite 表中的有效方法是什么?)
                  <i id='WgyYy'><tr id='WgyYy'><dt id='WgyYy'><q id='WgyYy'><span id='WgyYy'><b id='WgyYy'><form id='WgyYy'><ins id='WgyYy'></ins><ul id='WgyYy'></ul><sub id='WgyYy'></sub></form><legend id='WgyYy'></legend><bdo id='WgyYy'><pre id='WgyYy'><center id='WgyYy'></center></pre></bdo></b><th id='WgyYy'></th></span></q></dt></tr></i><div id='WgyYy'><tfoot id='WgyYy'></tfoot><dl id='WgyYy'><fieldset id='WgyYy'></fieldset></dl></div>
                  • <bdo id='WgyYy'></bdo><ul id='WgyYy'></ul>
                  • <legend id='WgyYy'><style id='WgyYy'><dir id='WgyYy'><q id='WgyYy'></q></dir></style></legend><tfoot id='WgyYy'></tfoot>
                  • <small id='WgyYy'></small><noframes id='WgyYy'>

                        <tbody id='WgyYy'></tbody>