• <small id='ncibd'></small><noframes id='ncibd'>

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

      <tfoot id='ncibd'></tfoot>

          <bdo id='ncibd'></bdo><ul id='ncibd'></ul>
      1. <i id='ncibd'><tr id='ncibd'><dt id='ncibd'><q id='ncibd'><span id='ncibd'><b id='ncibd'><form id='ncibd'><ins id='ncibd'></ins><ul id='ncibd'></ul><sub id='ncibd'></sub></form><legend id='ncibd'></legend><bdo id='ncibd'><pre id='ncibd'><center id='ncibd'></center></pre></bdo></b><th id='ncibd'></th></span></q></dt></tr></i><div id='ncibd'><tfoot id='ncibd'></tfoot><dl id='ncibd'><fieldset id='ncibd'></fieldset></dl></div>
      2. Django 模型:列的默认值

        Django models: default value for column(Django 模型:列的默认值)

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

            1. <legend id='xzgqQ'><style id='xzgqQ'><dir id='xzgqQ'><q id='xzgqQ'></q></dir></style></legend>

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

                  <tbody id='xzgqQ'></tbody>

                • <bdo id='xzgqQ'></bdo><ul id='xzgqQ'></ul>
                • 本文介绍了Django 模型:列的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有以下 Django 模型代码:

                  I have following Django model code:

                  status = models.PositiveIntegerField(default = 0b000)
                  comments_allowed = models.BooleanField(default = True) # whether comments are allowed to this post
                  

                  但我预计,它会生成类似的 SQL

                  But I expected, it would generate SQL like

                  `status` integer NOT NULL default '4',
                  `comments_allowed` bool NOT NULL default TRUE
                  

                  这没有发生,当我运行 manage.py sqlall appname 它会产生:

                  Which is not happening and when I run manage.py sqlall appname it produces:

                  `status` integer UNSIGNED NOT NULL,
                  `comments_allowed` bool NOT NULL
                  

                  深入研究 Django 的代码和谷歌搜索并没有给我什么,但 James Bennet 的评论认为 default 不会影响生成 SQL,但需要 Django 管理员.即使是这样,我如何获得预期的效果?

                  Delving into Django's code and googling gave me nothing, but James Bennet's comment that default is not assumed to affect generating SQL, but needed for Django admin. Even if so, how do I get desired effect?

                  我的 Django 版本是 1.3.0 最终版

                  My Django version is 1.3.0 final

                  推荐答案

                  请注意,default 参数也可以采用可调用对象:https://docs.djangoproject.com/en/dev/ref/models/fields/#default.这当然是 SQL 中无法重现的行为!因此,Django 不可能为每种可能的情况生成 SQL.看起来为了简单和一致性,他们选择不为任何情况生成 SQL.

                  Note that the default parameter can also take a callable object: https://docs.djangoproject.com/en/dev/ref/models/fields/#default. That is certainly a behavior that cannot be reproduced in SQL! So it would not be possible for Django to generate SQL for every possible case. It looks like for the sake of simplicity and consistency they have chosen not to generate SQL for any case.

                  这篇关于Django 模型:列的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 中循环结果集)
                  What is an efficient way of inserting thousands of records into an SQLite table using Django?(使用 Django 将数千条记录插入到 SQLite 表中的有效方法是什么?)
                  Prevent Django SQLite db from being overwritten while pushing to Heroku(防止 Django SQLite 数据库在推送到 Heroku 时被覆盖)
                  Writing an SQL query to SELECT item from the following table(编写 SQL 查询以从下表中选择项目)

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

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

                          <bdo id='EZ3du'></bdo><ul id='EZ3du'></ul>

                              <tbody id='EZ3du'></tbody>
                            <legend id='EZ3du'><style id='EZ3du'><dir id='EZ3du'><q id='EZ3du'></q></dir></style></legend>