且构网

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

Django 模型:列的默认值

更新时间:2023-01-30 10:32:57

请注意,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.