[Answered ]-Django (1.6.3) Model.save() method not working

1👍

Your primary key is an IntegerField, which means that Django doesn’t know it is supposed to autoincrement. Therefore it isn’t setting a value automatically.

Change the definition to use an AutoField instead.

1👍

After digging a bit more, I found that somewhere in the caller, transaction.atomic decorator was used. This was causing the write to db table to fail. I am updating this here hoping that this will help someone in future.

Thanks to all who replied.

Cheers!

0👍

You can just do the following

    def funcname(self, request):
        self.var = MyModel.objects.create(name='testName',description='testDescription',client_id=6, user=9, last_modified_by=9)

And Daniel commented about the id/pk field Django adds that automatically so no need to redeclare the field.

Leave a comment