問題:
What it the difference between running two commands:運行兩個命令有什麼區別:
foo = FooModel()
and和
bar = BarModel.objects.create()
Does the second one immediately create a BarModel
in the database, while for FooModel
, the save()
method has to be called explicitly to add it to the database?第二個是否立即在數據庫中創建一個BarModel
,而對於FooModel
,必須顯式調用save()
方法才能將其添加到數據庫中?
解決方案:
參考一: https://stackoom.com/question/1nucn參考二: Django Model() vs Model.objects.create()