<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                Why Mysql#39;s Group By and Oracle#39;s Group by behaviours are different(为什么 Mysql 的 Group By 和 Oracle 的 Group by 行为不同)
                MySQL GROUP BY DateTime +/- 3 seconds(MySQL GROUP BY DateTime +/- 3 秒)
                  <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>