更新时间: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.