MongoDB connection with Django i am getting below error after configuration - django

raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'

The best way to use MongoDB with Django is by using DJONGO package. It is a kind of django package developed only for the purpose to make Django compatible with MongoDB.
How to install djongo
pip install djongo
Also, Addi it requirement.txt to capture requirements for next time.
Update database settings as
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'your-db-name',
'CLIENT': {
'host': 'your-db-host',
}
}
}
Run migrations
python manage.py makemigrations <app_name>
and then run migrate changes to DB
python manage.py migrate
djongo is compatible with Python >=3.6 and MongoDB>=3.4.

After followed above steps i install python -m pip install pymongo[srv] it works i can run django project.
After applying default migrations i was getting errors in console so i followed below step.
Why I am getting "Not Implemented Error: Database objects do not implement truth value testing or bool()." while running makemigration cmd in django
Now i am not getting any kind of error and i am able to run django project with MongoDB successfully.

Related

How to check if database is present and migrated in Elastic Beanstalk?

I have been trying to troubleshoot 500 error, on a Django REST framework + ReactJS app. I think the migrate is not executing correctly.
The db-migrate.config file:
container_commands:
01_migrate:
command: "source $PYTHONPATH/activate pipenv run python manage.py migrate"
leader_only: true
DB_SETTINGS: eventually I want to change this to RDS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
eb deploy is successful.
I still run into the 500 error, on localmachine the same endpoint works perfectly.
How can I check whether the database on Elastic Beanstalk has the necessary migrations? Any other causes I should be looking into?

Page matching query does not exist - Django

I have site on django. I pull it from repo, create database and do migrations by
python manage.py migrate
runserver without errors, but when I try open the page(localhost:8000), this is error 'Page matching query does not exist'
It's probably because you haven't configured the urls.py file correctly. I recommend you to install django-extensions and to do python manage.py show_urls. There you will see all the paths you have available.

Postgis isn't an available database backend

I'm facing this error when setting up geodjango in a working django 1.9 app.
My app is living inside a amazon EC2 instance plus a RDS postgres instance.
The error is:
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3
What I've done:
Install GEOS, PROJ.4 and PostGIS as described in geodjango doc.
Install PostGIS in amazon RDS as described in amazon doc.
Modify my project settings.py to include:
INSTALLED_APPS = (... 'django.contrib.admin', ... 'django.contrib.gis')
GEOS_LIBRARY_PATH = '/usr/local/lib/libgeos_c.so'
DATABASES = { ... 'ENGINE': 'django.contrib.gis.db.backends.postgis' ...}
Modify my app models.py to import models from django.contrib.gis.db, instead of django.db
Any guess what I'm missing?
I had the same issue
i installed the osgeo
and then navigated to the missing libraries
> # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR =
> os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
> TEMPLATE_DIR=os.path.join(BASE_DIR,'templates')
and these were the missing libraries for me:
GDAL_LIBRARY_PATH = r'C:\OSGeo4W64\bin\gdal204.dll'
GEOS_LIBRARY_PATH=r'C:\OSGeo4W64\bin\geos_c.dll'
Run this command
sudo apt-get install binutils libproj-dev gdal-bin
This is described in this documentation
I had the same issue. I ran pip install gdal, which showed error messages about a libffi library missing on my system. After installing the correct library (libffi6 on AUR), I ran pip install gdal again and the issue was resolved.
I found that my libgdal library was causing me issues and giving me this error.
I'm working in windows under a conda environment running Django 1.11 and GDAL 2.0. Changing GDAL and django versions didnt seem to fix anything. However, setting the libgdal version to 1.11.2 seemed to clear the error up for me.

South migration for social auth

I am using south in my django project. I just added social_auth in settings.py, when i run this command:
python manage.py schemamigration social_auth --auto
It says:Nothing seems to have changed.
Please let me know how can i create tables for social auth, as by this command the table is not getting created.
django-social-auth works perfectly except that it needs South and it doesn't work with newer versions of Django.
To remove the dependencies form South in django-social-auth, simply remove the migrations created by South and create new ones using the newer migration engine from Django 1.7 >.
This is how I fixed it:
# Install django (if you haven't) and django-social-auth
(my_venv)$ pip install django django-social-auth
# Delete the South migrations
# Using a virtual environment: my_venv
# In case you use python3, replace
(my_venv)$ rm <path_to_my_venv>/lib/python2.7/site-packages/social_auth/migrations/000*
# Create an dummy django project
(my_venv)$ django-admin startproject asdf
Add django-social-auth to the asdf/settings.py file
### asdf/asdf/settings.py
...
INSTALLED_APPS = (
...
'social_auth',
)
...
Finally create the new migration for django-social-auth
# Create new migrations
$ python asdf/manage.py makemigrations social_auth
# Delete the dummy django-project
$ rm -r asdf
This fix will work for all the Django projects that work under the same virtual environment.
I don't think you need to generate migrations for social_auth, since this app should already have its migrations. Rather, you need to execute them, so after you added 'social_auth' in your settings you have to run only this command:
python manage.py migrate social_auth

Django: no such table: django_session

I have found several topics with this title, but none of their solutions worked for me. I have two Django sites running on my server, both through Apache using different virtualhosts on two ports fed by my Nginx frontend (using for static files). One site uses MySql and runs just fine. The other uses Sqlite3 and gets the error in the title.
I downloaded a copy of sqlite.exe and looked at the mysite.sqlite3 (SQLite database in this directory) file and there is indeed a django_session table with valid data in it. I have the sqlite.exe in my system32 as well as the site-packages folder in my Python path.
Here is a section of my settings.py file:
MANAGERS = ADMINS
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
'NAME': 'mysite.sqlite3', # 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.
}
}
I did use the python manage.py syncdb with no errors and just a "No Fixtures" comment.
Does anyone have any ideas what else might be going on here? I'm considering just transferring everything over to my old pal MySql and just ignoring Sqlite, as really it's always given me some kind of trouble. I was only using it for the benefit of knowing it anyway. I have no overwhelming reason why I should use it. But again, just for my edification does anyone know what this problem is? I don't like to give up.
After made any changes in code, run the following commands
manage.py makemigrations
manage.py migrate
it worked for me.
It could be that the server uses a different working directory than the manage.py command. Since you provide a relative path to the sqlite database, it is created in the working directory. Try it with an absolute path, e.g.:
'NAME': '/tmp/mysite.sqlite3',
Remember that you have to either run ./manage.py syncdb again or copy your current database with the existing tables to /tmp.
If it resolves the error message, you can look for a better place than /tmp :-)
run this in command shell:
python manage.py migrate
This fixed for me.
In case it helps anyone else: the problem for me was that I didn't have the django.contrib.sessions app uncommented in my INSTALLED_APPS. Uncommenting it, and rerunning a syncdb did the trick.
In my case the problem was that I forgot to run manage.py syncdb after I made some changes. When I did that the problem was solved.
When I run "manage.py runserver". If I run when I my current path is not in project dir.(such as python /somefolder/somefolder2/currentprj/manage.py runserver) I'll got the problem like you. solve by cd to project directory before run command.
One other possible cause can come from using:
./manage.py testserver
And then visiting the admin interface. This won't work because testserver creates a completely separate database in memory. If you want to visit the admin interface you need to use runserver.
This can happen if there are pending session migrations.
You have 17 unapplied migration(s). Your project may not work properly
until you apply the migrations for app(s): admin, auth, contenttypes,
sessions.
You can use the following command to run the migrations:
python manage.py migrate
This will fix the issue.
It happens may be beacause of undone migrations
• Executes following commands:
python manage.py showmigrations
python manage.py migrate --fake your_app_name zero
python manage.py showmigrations
• IF you are running on local machine, then remove file named 0001.init.py from migrations folder in your app
• Executes following commands:
python manage.py makemigrations
python manage.py migrate
• then run django server:
python manage.py runserver
had the same issue, my resolution was to simply add 'django.contrib.comments' to INSTALLED_APPS and run ./manage.py syncdb again.
I had similar problem for admin management. After several checks, run "python manage.py migrate" without assign APP's name (get "Apply all migrations: .....), then runserver and up on the web. It worked. I hope this could help.
You have unapplied migrations. your app may not work properly until they are applied.
Run 'python manage.py migrate' to apply them.
python manage.py migrate This one worked for me.
Maybe you have some unmigrated files.
Run
Python manage.py makemigrations appname
python manage.py migrate appname
python manage.py runserver
But if the error still continue
The run python manage.py migrate
The run server
create a schema and add its name under NAME in 'databases'
run manage.py syncdb
I had made some changes in Model which was not migrated to db properly. Using the command
manage.py makemigrations
fixed my problem. I hope this will help someone.
syncdb is obsolete try python manage.py makemigrations and python manage.py migrate solved the problem ,and donot forget to add the app name is the installed app in settings.py
I had the same problem so I ran
heroku run ls
and found that the db.sqlite3 file was missing from the server.
In my case, it was because I exempted it by adding it in .gitignore file.
Maybe it is not getting the path of db. Just add this to your settings.py:
import os
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
#modify your db NAME as below:
'NAME': os.path.join(PROJECT_PATH,'mysite.sqlite3'),
In my case I only focused on different project and did not migrate the main application.
so first:
manage.py makemigrations
manage.py migrate
and then to the project's:
manage.py makemigrations <my other project name>
manage.py migrate <my other project name>
Had this problem too. Restarting postgres and apache2 did it for me. Makes me wonder if there was some kind of sqlite process left over which wasn't removed until you fiddled with the files or something.
I had this issue in a different scenario. I am new to Django and cloned a repository from github to practice on it. The file db.sqlite3 was also copied. But there was no django_session in it. When I did
./manage.py showmigrations
.. I found out that there were some migrations. But the tables were missing in sqlite, as I never ran migrate. My issue was resolved when I ran the migrate command. Hope this helps django newbies like me.
./manage.py migrate
Add 'django.contrib.sessions', line in INSTALLED_APPS
Run below commands from django shell
python manage.py makemigrations #check for changes
python manage.py migrate #apply changes in DbSQLite
python manage.py syncdb #sync with database
django_session will appear in database with (session_key, session_data , expire_date)
In my case, I had to erase the 'sessions' entry in the django_migrations table and run makemigrations and migrate afterwards. That created the django_session table.
For me, it was that I updated settings.py, ran the migrations, but the systemd process was still using SQLite because I did not reload it. Doing systemctl restart service_name solved the problem.
And it may be a case you are getting this error because you forget to run query python manage.py migrate before creating super user
If you are tired of using makemigrations and migrate but the error is same no such table django_session. Then just have a look to you code somewhere or the other you using session or calling it. Just comment the code where you are using session and then run the command makemigrations and migrate respectively. It 100% solve your issue.The cause of this error is that you deleted your migrations folder and database file that is the reason you are getting this error.Feel free to ask if problem is not solve
This worked for me.
From https://docs.djangoproject.com/en/2.2/topics/http/sessions/
Using database-backed sessions -
If you want to use a database-backed session, you need to add 'django.contrib.sessions' to your INSTALLED_APPS setting.
Once you have configured your installation, run manage.py migrate to install the single database table that stores session data.
Please try the following command when you change on your code
manage.py makemigrations
manage.py migrate
Simply run this commands
python manage.py makemigrations
python manage.py migrate
python manage.py runserver
it's simple just run the following command
python ./manage.py migrate
python ./manage.py makemigrations AppName