What's the error in my project?

随声附和 提交于 2020-01-03 05:17:06

问题


I'm using mongodb for my python(2.7) project with django framework..when i give python manage.py runserver it will work but if i sync the db (python manage.py syncdb) the following error displayed in terminal

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)

and

django.db.utils.DatabaseError: Ordering can't span tables on non-relational backends (content_type__app_label)

How to solve this problem?


回答1:


You need to use Django-nonrel instead of Django.




回答2:


I've used mongoengine with django but you need to create a file like mongo_models.py for example. In that file you define your Mongo documents. You then create forms to match each Mongo document. Each form has a save method which inserts or updates whats stored in Mongo. Django forms are designed to plug into any data back end ( with a bit of craft )

BEWARE: If you have very well defined and structured data that can be described in documents or models then don't use Mongo. Its not designed for that and something like PostGreSQL will work much better.

  • I use PostGreSQL for relational or well structured data because its good for that. Small memory footprint and good response.
  • I use Redis to cache or operate in memory queues/lists because its very good for that. great performance providing you have the memory to cope with it.
  • I use Mongo to store large JSON documents and to perform Map and reduce on them ( if needed ) because its very good for that. Be sure to use indexing on certain columns if you can to speed up lookups.

Don't circle to fill a square hole. It won't fill it.

I've seen too many posts where someone wanted to swap a relational DB for Mongo because Mongo is a buzz word. Don't get me wrong, Mongo is really great... when you use it appropriately. I love using Mongo appropriately



来源:https://stackoverflow.com/questions/10188165/whats-the-error-in-my-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!