I get django-nonrel, djangotoolbox and mongodbengine from github, and the setting.py is as following:
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'admin', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
)
ROOT_URLCONF = 'ptl.urls'
TEMPLATE_DIRS = ('/Users/bxshi/PycharmProjects/ptl/templates',)
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
)
Except that settings.py, I do not have any other .py file in my project.
The error I got is that:
BaoxuShis-MacBook:ptl bxshi$ python manage.py syncdb
Creating tables ...
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_manager(settings)
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/Library/Python/2.7/site-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Library/Python/2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Library/Python/2.7/site-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
File "/Library/Python/2.7/site-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
interactive=interactive, db=db)
File "/Library/Python/2.7/site-packages/django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
File "/Library/Python/2.7/site-packages/django/contrib/contenttypes/management.py", line 11, in update_contenttypes
content_types = list(ContentType.objects.filter(app_label=app.__name__.split('.')[-2]))
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 84, in __len__
self._result_cache.extend(self._iter)
File "/Library/Python/2.7/site-packages/django/db/models/query.py", line 275, in iterator
for row in compiler.results_iter():
File "build/bdist.macosx-10.7-intel/egg/djangotoolbox/db/basecompiler.py", line 335, in results_iter
File "build/bdist.macosx-10.7-intel/egg/djangotoolbox/db/basecompiler.py", line 430, in build_query
File "build/bdist.macosx-10.7-intel/egg/django_mongodb_engine/compiler.py", line 160, in add_filters
File "build/bdist.macosx-10.7-intel/egg/django_mongodb_engine/compiler.py", line 168, in add_filters
ValueError: need more than 3 values to unpack
I find something related to this error about mongodbengine, a thread on BBS talk about that, but it says this is already fixed.
Simply use the official installation instructions on https://django-mongodb-engine.readthedocs.org/en/latest/topics/setup.html
Related
I am creating a app in django and I want to fetch data from mongolab.
But,I don't know how to connect mongolab to django.
I had connect mongodb to django but now I want to connect with mongolab.
How to do this?
I have used this in my setting.py file,
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django.contrib.admindocs',
'djangotoolbox',
'app'
)
And in DATABASE:,
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': '*****',
'USER': '*****',
'PASSWORD': '******',
'HOST': 'ds129469.mongolab.com',
'PORT': '26469'
}
}
And after running command, python manage.py runserver
I get following error,
life#life-All-Series:~/mongo/env1/project7/project$ python manage.py runrver
/home/life/.local/lib/python2.7/site-packages/djangotoolbox/db/utils.py:1: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead.
from django.db.backends.util import format_number
/home/life/.local/lib/python2.7/site-packages/djangotoolbox/db/utils.py:1: RemovedInDjango19Warning: The django.db.backends.util module has been renamed. Use django.db.backends.utils instead.
from django.db.backends.util import format_number
Performing system checks...
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function wrapper at 0x7fbad4b24c08>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/autoreload.py", line 229, in wrapper
fn(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check_migrations()
File "/usr/lib/python2.7/dist-packages/django/core/management/commands/runserver.py", line 168, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "/usr/lib/python2.7/dist-packages/django/db/migrations/executor.py", line 19, in __init__
self.loader = MigrationLoader(self.connection)
File "/usr/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 47, in __init__
self.build_graph()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/loader.py", line 191, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 59, in applied_migrations
self.ensure_schema()
File "/usr/lib/python2.7/dist-packages/django/db/migrations/recorder.py", line 49, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/home/life/.local/lib/python2.7/site-packages/django_mongodb_engine/base.py", line 179, in table_names
return self.connection.database.collection_names()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/database.py", line 488, in collection_names
ReadPreference.PRIMARY) as (sock_info, slave_okay):
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 699, in _socket_for_reads
with self._get_socket(read_preference) as sock_info:
File "/usr/lib/python2.7/contextlib.py", line 17, in __enter__
return self.gen.next()
File "/home/life/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 663, in _get_socket
server = self._get_topology().select_server(selector)
File "/home/life/.local/lib/python2.7/site-packages/pymongo/topology.py", line 121, in select_server
address))
File "/home/life/.local/lib/python2.7/site-packages/pymongo/topology.py", line 97, in select_servers
self._error_message(selector))
pymongo.errors.ServerSelectionTimeoutError: ds129469.mongolab.com:29469: [Errno -2] Name or service not known
I'm trying to create ContentType reference (https://docs.djangoproject.com/en/1.8/ref/contrib/contenttypes/#generic-relations)
myobj/models.py:
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
class TaggedItem(models.Model):
tag = models.SlugField()
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')
When I start the test (manage.py test -v3), I get traceback:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/alexander/.local/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/home/alexander/.local/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/home/alexander/.local/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/alexander/.local/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=True,
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 179, in handle
created_models = self.sync_apps(connection, executor.loader.unmigrated_apps)
File "/home/alexander/.local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 317, in sync_apps
cursor.execute(statement)
File "/home/alexander/.local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/alexander/.local/lib/python2.7/site-packages/django/db/utils.py", line 97, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/alexander/.local/lib/python2.7/site-packages/django/db/backends/utils.py", line 62, in execute
return self.cursor.execute(sql)
django.db.utils.ProgrammingError: ERROR: reference "django_content_type" does not exist
my settings.py:
...
INSTALLED_APPS = (
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.staticfiles',
'myobj',
)
...
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mydb', # Or path to database file if using sqlite3.
'USER': 'user', # Not used with sqlite3.
'PASSWORD': 'pass', # Not used with sqlite3.
'HOST': '127.0.0.1', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '5432', # Set to empty string for default. Not used with sqlite3.
'TEST_NAME': "testdb_%i_%i" % (random.randrange(1,1000000),random.randrange(1,10000000)),
}
}
...
Postgresql log:
ALTER TABLE "myobj_taggeditem" ADD CONSTRAINT "myob_content_type_id_708726b4e928b107_fk_django_content_type_id" FOREIGN KEY ("content_type_id") REFERENCES "django_content_type" ("id") DEFERRABLE INITIALLY DEFERRED
ERROR: reference "django_content_type" does not exist
If I change DB engine to SQLite everythink is ok.
Whats wrong with it?
I'm using django 1.8
You must create migrations for your myobj app. An unmigrated app cannot depend on a migrated app.
Simply run python manage.py makemigrations myobj and it will create the initial migrations for your app.
The reason it "works" on SQLite3 is that foreign key constraints are not enforced in SQLite by Django.
I am trying to use Mongodb with in my Django.
Below there are connection settings in settings.py
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email#example.com'),
)
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': '',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': 27017,
}
}
when I am trying to run python manage.py syncdb I am getting an error like this:
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/__init__.py", line 429, in execute_from_command_line
utility.execute()
File "/home/sakeer/workspace/entevirtual/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/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django/core/management/commands/syncdb.py", line 59, in handle_noargs
tables = connection.introspection.table_names()
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 76, in table_names
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 106, in __getattr__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/django_mongodb_engine-0.4.0-py2.7.egg/django_mongodb_engine/base.py", line 133, in _connect
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1025, in __getitem__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/mongo_client.py", line 1014, in __getattr__
File "/home/sakeer/workspace/entevirtual/lib/python2.7/site-packages/pymongo-2.4.2-py2.7-linux-x86_64.egg/pymongo/database.py", line 74, in __init__
django.core.exceptions.ImproperlyConfigured: name must be an instance of basestring
i am using django 1.3
thanks in advance
I've never used mongodb with django, but I'll take a stab just by following the trace. You need to add a value to the NAME setting in your DB configuration
DATABASES = {
'default': {
'ENGINE': 'django_mongodb_engine',
'NAME': 'foobar',
'USER': '',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': 27017,
}
}
The error is being thrown here in pymongo which is created around here via django_mongo_engine
In attempting to run ./manage.py runserver or shell or any other command for that matter, I'm getting the error: You must define a 'default' database.
I'm running this in a virtualenv and settings.py includes DATABASE_NAME, along with Host, Port and Engine. Where is django expecting definition of the default database?
Here's the traceback:
(env)fox-ser01:common wmfox3$ ./manage.py shell
Traceback (most recent call last):
File "./manage.py", line 31, in <module>
execute_manager(settings)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 442, in execute_manager
utility.execute()
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 220, in execute
output = self.handle(*args, **options)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/base.py", line 351, in handle
return self.handle_noargs(**options)
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/core/management/commands/shell.py", line 46, in handle_noargs
from django.db.models.loading import get_models
File "/Users/wmfox3/Sites/photo_project/env/src/django/django/db/__init__.py", line 12, in <module>
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
django.core.exceptions.ImproperlyConfigured: You must define a 'default' database
DATABASE_NAME is deprecated since django 1.2 so if you're using newer version, you should use the new way of defining databases:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'mydatabase'
}
}
define db name is settings.py
DATABASE
Below is an example
DATABASES = {
'default': {
'ENGINE': 'mysql',
'NAME': 'xyz', # db name
'USER': 'root',
'PASSWORD': 'password',
'HOST': '',
'PORT': '',
}
}
In settings.DATABASES.
I am trying to run django on my ubuntu lucid, but I get the following:
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_manager(settings)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 438, in execute_manager
utility.execute()
File "/usr/local/lib/python2.6/dist-packages/django/core/management/__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.6/dist-packages/django/core/management/base.py", line 209, in execute
translation.activate('en-us')
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 66, in activate
return real_activate(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/functional.py", line 55, in _curried
return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/__init__.py", line 36, in delayed_loader
return getattr(trans, real_name)(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 193, in activate
_active[currentThread()] = translation(language)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 176, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
File "/usr/local/lib/python2.6/dist-packages/django/utils/translation/trans_real.py", line 159, in _fetch
app = import_module(appname)
File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/home/gruszczy/Programy/bozorth/../bozorth/notifications/__init__.py", line 2, in <module>
from django.db.models.signals import post_save
File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py", line 75, in <module>
connection = connections[DEFAULT_DB_ALIAS]
File "/usr/local/lib/python2.6/dist-packages/django/db/utils.py", line 92, in __getitem__
conn = backend.DatabaseWrapper(db, alias)
File "/usr/local/lib/python2.6/dist-packages/django/db/backends/sqlite3/base.py", line 154, in __init__
super(DatabaseWrapper, self).__init__(*args, **kwargs)
TypeError: __init__() takes exactly 2 arguments (3 given)
I have created and empty project and only changed database settings:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'test.db3', # Or path to database file if using sqlite3.
'USER': '', # Not used with sqlite3.
'PASSWORD': '', # Not used with sqlite3.
'HOST': '', # Set to empty string for localhost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}
Am I lacking some dependency?
try to define databases in Multiple database format