Django not creating id field in mongodb database


I am working on a Django project which uses MongoDB as database. I am using Djongo as plugin to interface Django with MongoDB.

In one of my models, when i try to save, the id field is not saved in MongoDB. But, if i force a value to id field before saving the object, the id field is stroed in database.

I have other models in my project and they have id fields stored in MongoDB. So, the issue is specific to a model.

I checked my migration files and id field is defined properly. Looks like when save the object, the id field is not stored for specific model.

Can you please suggest how i can debug this issue?

Hi Chethan-7,

Here are some things to try to debug the issue:

  • If you start on a fresh db (re-run all migrations), does this still happen?
  • Is that model different in any other way from the other models?
  • Is the internal djongo schema correct for this model? The docs warn about the auto-increment functionality being something djongo has to implement.