问题:
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()