且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Django模型:列的默认值

更新时间:2023-01-30 10:50:36

请注意,默认值参数也可以使用可调用对象: https://docs.djangoproject.com/en/dev/ref/models/fields /#默认。这当然是一个不能在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.