Im been looking at mongo-engine. From what I can see to allow you to use the ListField, DictField etc field types and to use the Django ORM style of db models (with a MongoDB) you need use django-nonrel/djangotoolbox (??)
Is there anyway to intergrate MongoDB with Django without using Django-norel.
I want to use django ORM, mongodb, listfield, dictfield whilst using my current django version.
Thanks,
You can use MongoEngine directly with Django; it does not use or require django-nonrel classes.
The MongoEngine documentation includes a full section on Django Support including Authentication, Custom User Models, Sessions, Storage, and Shortcuts.
Per the MongoEngine to Django connection instructions, you need to ignore the standard database settings (unless you also plan to use an ORM in your project), and instead call connect() somewhere in the settings module.
You also need to add a dummy database backend to your settings.py (if you are not using another database backend):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy'
}
}
Related
I'm using Django for backend, but for some reason, I want to use Laravel beside Django and share the database between them. so the same database for Django and Laravel. but the problem is that Django migrations are not equal to Laravel migrations so the database is different from ( for example constraints and indexes and some other options).
Is this going to break backend if I use Django as the primary database and use Laravel as a secondary backend?
If true, how I can use Django and Laravel in the same database?
Your database does not depend on Django or Laravel. It just stores data.
Constraints, triggers, indexes, etc are stored on the database itself, and they are completely independent of your framework. Frameworks just abstract the methods and provide easy methods to manage your database. At the core, they use the same commands which are provided by the database. The names of constraints are irrelevant, you can give whatever names you want, frameworks just provide their own uniform naming pattern, which can be customized by the user. So they can be used on both Django and Laravel or any other framework/programming language. That's the main purpose of having a database, to store data in a structured manner so it can be used by any language/framework
Since you already have migrations in Django, there's no need to create the migrations again in laravel. Just reuse the Django database and make your laravel application to properly handle the data (that part is completely in your control)
Like in phpmyadmin, we have an visual interface to manage fields. Can we do the same thing in Django?
If your Django connected database is e.g. PostgreSQL, you could use pgAdmin4 (https://www.pgadmin.org/). So it is actually not about managing the tables in Django but in a database tool (visually). To manipulate your database schema you will have to use Models in your Django application (https://docs.djangoproject.com/en/2.2/topics/db/models/).
We have a Django application that has been in production since Django 1.1. Over the years, we've manually added bells and whistles to the production PostgreSQL db that weren't at the time overtly supported by Django's db automation, especially in the form of custom indexes.
Django's come a long way since 1.1, and now w/ 1.10 I'm pretty sure the migration framework supports all the custom features we've added manually. Is there any automated tool which will compare a database to the models, and generate migrations to bring the models up to date with the db?
This is built into django, you can just run inspectdb
manage.py inspectdb
Introspects the database tables in the database pointed-to by the NAME setting and outputs a Django model module (a models.py file) to standard output. You may choose what tables to inspect by passing their names as arguments.
Use this if you have a legacy database with which you’d like to use Django. The script will inspect the database and create a model for each table within it.
I am evaluating whether I want to use mongoDB with django for my next project. What I am not sure about, though, is what functionality (ORM, admin, forms, etc.) I loose when I use a DB backend that is not officially supported.
I consider using the mongodb-engine.
So, you have Django-mongoadmin and Django-mongonaut for django-admin stuff. Also
Django-mongodbforms for model forms. MongoEngine as ORM. But this modules are pretty raw and unstable so use it with wariness.
I want to use MongoDB as database backend for my Django project. Although there are many discussions on the net, I'm having troubles to integrate them well.
My goals:
use default Django (so no django-nonrel, which is still to 1.3)
integrate them so that authentication is backed by MongoDB (i.e. the
default User model) as well as the sessions thing.
if possible, still have a ORM-like query system
As I understand that, mongoengine could meet all my requirements, but I'm having troubles making it work correclty.
Docs say to ignore DATABASES setting. If I don't specify it, Django raises an error, while if I fill it, Django creates that database and does not use my MongoDB instance, even though I call connect() later in the file. When I run syncdb Django uses the other database (the one I specified in the DATABASES setting) and not MongoDB. So when I fire up MongoDB shell I can see the database is created, but the only collection is startup_log, which I never created and I suspect it's created automatically.
This might be a change in the default requirements does adding a dummy backend to your settings help?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.dummy'
}
}