How does unique_together work in Django-nonrel?

442 Views Asked by At

I am using django-nonrel and django-mongodb engine.

In engine's documentation, it says that it supports django's Meta options.

I tried using unique_together in a model as such:

class Bottler(models.Model):

    location = models.CharField(max_length=20)

    source = models.CharField(max_length=20)

    transactionID = models.CharField()

    class Meta:
        unique_together = (("location","source"),)

However this doesn't seem to have worked since I could create duplicates without any error being raised.

I know unique_together is enforced at the database level.

What does that translate to in MongoDB? Do I have to validate it manually?

2

There are 2 best solutions below

0
On BEST ANSWER

You need to run syncdb in order to sync database indices.

0
On

Somehow syncbd will not update your indexes in mongodb. What you can try (if possible in your situation) is to delete the collection and then run syncdb. In my case it did create the indexes then.