__init__() got an unexpected keyword argument 'user'

前端 未结 4 537
暗喜
暗喜 2020-12-25 12:14

i am using Django to create a user and an object when the user is created. But there is an error

__init__() got an unexpected keyword argument \'user\'<

4条回答
  •  自闭症患者
    2020-12-25 13:13

    LivingRoom.objects.create() calls LivingRoom.__init__() - as you might have noticed if you had read the traceback - passing it the same arguments. To make a long story short, a Django models.Model subclass's initializer is best left alone, or should accept *args and **kwargs matching the model's meta fields. The correct way to provide default values for fields is in the field constructor using the default keyword as explained in the FineManual.

提交回复
热议问题