Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexes aren't synced after db creation #124

Open
Psycojoker opened this issue Apr 16, 2012 · 14 comments
Open

Indexes aren't synced after db creation #124

Psycojoker opened this issue Apr 16, 2012 · 14 comments
Milestone

Comments

@Psycojoker
Copy link

(was: "[documentation] lack of information on indexes creation")

Hello,

Here http://django-mongodb.org/reference/model-options.html we can read "and generates the corresponding MongoDB indexes on syncdb." which is totally true but this lack 2 informations:

  • the syncdb will only create indexes at the db creation (maybe it's a mongodb limitation but that sound strange to me)
  • there is no information on how to add indexes after the db creation (I guess this is supposed to be done in mongo shell)

Kind regards,

@jonashaag
Copy link
Contributor

Doesn't look like a documentation issue but a program bug. Can you try that with the latest devel of all projects? If it's still an issue, tests+patches welcome :-)

@Psycojoker
Copy link
Author

I have tried it with a dummy project before reporting using the last version of the hg/git (hg+https://bitbucket.org/wkornewald/django-nonrel hg+https://bitbucket.org/wkornewald/djangotoolbox git+https://github.com/django-nonrel/mongodb-engine) so I can confirm you this issue.

@jonashaag
Copy link
Contributor

Sorry, I meant the devel branches of the the GitHub repos: https://github.com/django-nonrel

@Psycojoker
Copy link
Author

After severals attemps and even recreating a totally new project I'm unable to syncdb with the devel branch (and same branch for the 2 other projects).

Error:

(ve)psycojoker@griboiedov dummy % python manage.py syncdb
Traceback (most recent call last):
  File "manage.py", line 14, in <module>
    execute_manager(settings)
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/__init__.py", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 7, in <module>
    from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/core/management/sql.py", line 6, in <module>
    from django.db import models
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/db/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/db/utils.py", line 93, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/psycojoker/code/django/nonrel-indexes-bugs2/ve/lib/python2.7/site-packages/django/db/utils.py", line 51, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
    'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils

What am I missing?

@jonashaag
Copy link
Contributor

No module named utils?! WTF. Are you sure you've installed MongoDB Engine correctly? Didn't delete any files? Is it importing the correct package?

@Psycojoker
Copy link
Author

Yeah, that was pretty much my reaction.

requirements.txt:

hg+https://bitbucket.org/wkornewald/django-nonrel
hg+https://bitbucket.org/wkornewald/djangotoolbox
git+https://github.com/django-nonrel/mongodb-engine@develop

My procedure looks like that, in an empty directory:

virtualenv --no-site-packages --distribute ve; source ve/bin/activate
pip install -r requirements.txt
deactivate; source ve/bin/activate
django-admin.py startproject dummy
edit the settings files to set up the db
python manage.py syncdb

And then I got the error.

'python -c "import django_mongodb_engine"' doesn't return any error.

@jonashaag
Copy link
Contributor

You should use the devel branches of the GitHub repos for all projects, i.e.

git+https://github.com/django-nonrel/django-nonrel@develop
git+https://github.com/django-nonrel/djangotoolbox@develop
git+https://github.com/django-nonrel/mongodb-engine@develop

@Psycojoker
Copy link
Author

Oh strange, the setup recommand the hg repository (that don't have a develop branch), maybe you should change that: http://django-mongodb.org/topics/setup.html

Interesting, this time at the first syncdb I've got the site ID bug (that I don't have on master) http://django-mongodb.org/troubleshooting.html but the fix indicated didn't worked (manage.py tellsideid got me a django.contrib.sites.models.DoesNotExist: Site matching query does not exist.). I've add to disable the site app in the INSTALLED_APP.

Anyway, I can now confirm that the initial bug is also affecting develop branch :)

@jonashaag
Copy link
Contributor

Oh strange, the setup recommand the hg repository (that don't have a develop branch), maybe you should change that: http://django-mongodb.org/topics/setup.html

I think you confused things a bit :-) The repos recommended in the setup docs are the stable ones. I was asking you to confirm the bug against the unstable repos (develop branches) in my first answer: "Can you try that with the latest devel of all projects?"

Anyway. It's a bug. Marking for milestone 0.5

@Psycojoker
Copy link
Author

I think you confused things a bit :-) The repos recommended in the setup docs are the stable ones. I was asking you to confirm the bug against the unstable repos (develop branches) in my first answer: "Can you try that with the latest devel of all projects?"

That's not very important but it's just that I didn't realised that there were git repository, I've just looked at the mercurial one and didn't found any develop branch ;)

Thanks for your quick reactions :)

@risingsunomi
Copy link

I am still getting this error and I have tried everything I can to fix it (setting the right python path and also setting the django_settings_module which afterward allowed me to import django_mongodb_engine in the python interactive shell without any errors). I am on Mac OSX 10.7.3 using python 2.7.1

Here is the error I am getting when I try running runserver or run_gunicorn

runserver

Validating models...

Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x104f50ed0>>
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/commands/runserver.py", line 91, in inner_run
self.validate(display_num_errors=True)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/base.py", line 266, in validate
num_errors = get_validation_errors(s, app)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/validation.py", line 23, in get_validation_errors
from django.db import models, connection
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/init.py", line 40, in
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/init.py", line 34, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 92, in getitem
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 44, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils

run_gunicorn (also syncdb)

Traceback (most recent call last):
File "./manage.py", line 10, in
execute_from_command_line(sys.argv)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/init.py", line 443, in execute_from_command_line
utility.execute()
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/init.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/init.py", line 261, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/core/management/init.py", line 69, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/utils/importlib.py", line 35, in import_module
import(name)
File "/Library/Python/2.7/site-packages/gunicorn-0.14.5-py2.7.egg/gunicorn/management/commands/run_gunicorn.py", line 17, in
from django.db.backends import BaseDatabaseWrapper, DatabaseError
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/init.py", line 40, in
backend = load_backend(connection.settings_dict['ENGINE'])
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/init.py", line 34, in getattr
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 92, in getitem
backend = load_backend(db['ENGINE'])
File "/Library/Python/2.7/site-packages/Django-1.4-py2.7.egg/django/db/utils.py", line 44, in load_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django_mongodb_engine' isn't an available database backend.
Try using django.db.backends.XXX, where XXX is one of:
'dummy', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named utils

I have installed and re-installed the module over and over again to make this work but still nothing.

Is there a solution to this yet? I am also doing this on django 1.4

@risingsunomi
Copy link

Just now also tried reinstalling with a requirements.txt with:

git+https://github.com/django-nonrel/django-nonrel@develop
git+https://github.com/django-nonrel/djangotoolbox@develop
git+https://github.com/django-nonrel/mongodb-engine@develop

using pip and still the same error. Even when running this with pip it downgraded my django install to 1.3.1 and still the same errors...

@risingsunomi
Copy link

Hi,

I got it to work had to copy the django folder in the django-nonrel zip file into a library folder then include it in my pythonpath then I got it work.

@JohnnyZhao
Copy link

this solved my problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants