我正在使用mongodb为我的python(2.7)项目使用django框架..当我给 python manage.py runserver它会工作,但如果我同步db(python manage.py syncdb)终端中显示以下错误
Creating tables ...
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/usr/lib/pymodules/python2.7/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/lib/pymodules/python2.7/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/usr/lib/pymodules/python2.7/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/usr/lib/pymodules/python2.7/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/usr/lib/pymodules/python2.7/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/usr/lib/pymodules/python2.7/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/usr/lib/pymodules/python2.7/django/contrib/auth/management/__init__.py", line 41, in create_permissions
"content_type", "codename"
File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 107, in _result_iter
self._fill_cache()
File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 772, in _fill_cache
self._result_cache.append(self._iter.next())
File "/usr/lib/pymodules/python2.7/django/db/models/query.py", line 959, in iterator
for row in self.query.get_compiler(self.db).results_iter():
File "/usr/local/lib/python2.7/dist-packages/djangotoolbox/db/basecompiler.py", line 229, in results_iter
for entity in self.build_query(fields).fetch(low_mark, high_mark):
File "/usr/local/lib/python2.7/dist-packages/djangotoolbox/db/basecompiler.py", line 290, in build_query
query.order_by(self._get_ordering())
File "/usr/local/lib/python2.7/dist-packages/djangotoolbox/db/basecompiler.py", line 339, in _get_ordering
raise DatabaseError("Ordering can't span tables on non-relational backends (%s)" % order)
和
django.db.utils.DatabaseError: Ordering can't span tables on non-relational backends (content_type__app_label)
如何解决这个问题?
答案 0 :(得分:4)
你需要使用Django-nonrel而不是Django。
答案 1 :(得分:2)
我已经将mongoengine与django一起使用,但你需要创建一个像mongo_models.py这样的文件。在该文件中,您可以定义Mongo文档。然后,您创建表单以匹配每个Mongo文档。每个表单都有一个save方法,用于插入或更新存储在Mongo中的内容。 Django表单旨在插入任何数据后端(使用一些工艺)
注意:如果您有非常好的定义和结构化数据,可以在文档或模型中描述,那么不要使用Mongo。它不是为此而设计的,像PostGreSQL这样的东西会更好。
不要圈起来填补方孔。它不会填补它。
我看过很多帖子,有人想要为Mongo交换关系数据库,因为Mongo是一个流行词。不要误会我的意思,Mongo真的很棒......当你适当地使用它时。我喜欢适当地使用Mongo