I built up a website by using django 1.3, Mongodb, and django-mongo-engine. When I run the server by using "manage.py runserver", it is successful. But when I try to do unit testing by "manage.py test", it somehow fails.
Here is the settings.py about database:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'sean_test',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
And this is the error message in testing:
....Problem installing fixture 'c:\Python27\lib\sitepackages\django\contrib\auth\fixtures\authtestdata.json': Traceback(most recent call last):
File "c:\Python27\lib\site-packages\django\core\management\commands\loaddata.py", line 174, in handleobj.save(using=using)
File "c:\Python27\lib\site-packages\django\core\serializers\base.py", line 165, in savemodels.Model.save_base(self.object, using=using, raw=True)
File "c:\Python27\lib\site-packages\django\db\models\base.py", line 573, in save_baseresult = manager._insert(values, return_id=update_pk, using=using)
File "c:\Python27\lib\site-packages\django\db\models\manager.py", line 195, in _insertreturn insert_query(self.model, values, **kwargs)
File "c:\Python27\lib\site-packages\django\db\models\query.py", line 1438, in insert_queryreturn query.get_compiler(using=using).execute_sql(return_id)
File "c:\Python27\lib\site-packages\djangotoolbox\db\basecompiler.py", line 369, in execute_sqlvalue = self.convert_value_for_db(db_type, value)
File "c:\Python27\lib\site-packages\django_mongodb_engine\compiler.py", line 67, in wrapperreturn func(*args, **kwargs)
File "c:\Python27\lib\site-packages\django_mongodb_engine\compiler.py", line 307, in convert_value_for_dbraise InvalidId(msg)
InvalidId: AutoField (default primary key) values must be strings representing an ObjectId on MongoDB (got u'1' instead)
I know that the django uses integer while mongodb uses string for the primary key, but I don't know why the test will fail when the "runserver" succeeds. Any idea about how to fix this problem?
Thanks!