geo django The specified module could not be found - django

i'm trying to make location based web application with django and sub framework (geodjango) and postgresql - postgis , windows 10
i've also installed GDAL through GDAL-2.4.1-cp37-cp37m-win_amd64.whl,geos, and added this line to settings.py file
GDAL_LIBRARY_PATH = 'C:\\OSGeo4W64\\bin\\gdal111.dll'
and database
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': '...',
'USER':'....',
'HOST':'localhost',
'PASSWORD':'....',
'PORT':'5432',
}
}
but still getting this error while im trying to python manage.py makemigrations/migrate
OSError: [WinError 126] The specified module could not be found
and when i run python manage.py runserver i get this error
LookupError: No installed app with label 'admin'.

I put gdal300.dll as target and that worked.

Related

KeyError: 'DB_NAME' when doing makemigrations in django

I store all my secrets and database params in the dev.env file.
I have 3 different settings files - base, dev and prod.
There is an SQLite database in base, and I want to connect to Postgres in dev.
So I upload my secrets with the environment variable in my dev setting file like this:
from dotenv import load_dotenv
load_dotenv(os.environ.get('ENV_CONFIG', ''))
And I override my database settings in dev settings file:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ['DB_NAME'],
'USER': os.environ['DB_USER'],
'PASSWORD': os.environ['DB_PASS'],
'HOST': os.environ['DB_HOST'],
'PORT': os.environ['DB_PORT'],
}
}
But when I run makemigrations with dev settings file:
./manage.py makemigrations --settings=app.settings.dev
I get an error:
File "/Users/admin/Desktop/Programming/Python/UkranianFunds/src/app/settings/dev.py", line 35, in <module>
'NAME': os.environ['DB_NAME'],
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/os.py", line 679, in __getitem__
raise KeyError(key) from None
KeyError: 'DB_NAME'
I checked and my secret with the key DB_NAME clearly appears in the settings file - I printed it successfully. The name of the database is correct.
What are other reasons that cause that?
Your loaded dev.env file does not contain 'DB_NAME' as a key.
I solved it by replacing os.environ['DB_NAME'] to os.environ.get('DB_NAME').
Weird situation for me because the problem occurred only when I did makemigrations.
After I migrated to Postgres, I tried to run the app with os.environ['DB_NAME'] and it worked fine.
So it seems that the KeyError is being raised only during makemigrations.

Heroku doesnt migrate models on Django

I just deploy my Django app to Heroku but I cant migrate my migrations to heroku. First I run :
heroku run python manage.py migrate all the migrations list as OK but when I showmigrations, none of them is migrating (all blank [ ]).
Then I try heroku run bash and migrate from there, everything seems ok even showmigrations from bash showing all of the migrations is working. I even manage to create a superuser. But when I open my admin page and log in with superuser it shows 'account.account' table does not exist and when I check showmigrations again all of the migrations are gone. I have been repeating this migration over and over and still can't figure this out.
Does anyone know what I am doing wrong here?
Edit :
I don't know if this is related but when I push my project to Heroku the first time, I'm using Postgre with this setting :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': DB_NAME,
'USER': DB_USER,
'PASSWORD': DB_PASSWORD,
'HOST': 'localhost',
'PORT': '5432',
}
}
but when I try to run migrations it shows an error something like cant access localhost with 5432 port, it turns out that Heroku trying to access postgre in my localhost instead of using Heroku Postgres. The solution I found is to dump my db and reload it to Heroku. And since I don't know how to set that up. I just comment that postgre setting and replace it with default django setting :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
create my dbsqlite file, running migrations again then once again push it to Heroku, hoping to find an easy way out but instead ended up in this problem
I'd recommend you to push a migrated project to heroku that is
python manage.py migrate
then push that migrated project to heroku
the reason your superuser doesn't get stored while creating superuser from heroku bash is because heroku has an ephemeral drive i.e heroku clears all the modified data from orignal push after equal interval of time.
It turns out that I forgot to install django-heroku. More on this : https://devcenter.heroku.com/articles/django-app-configuration

pymongo.errors.OperationFailure: unsupported type in filter

I am working on Project Django with MongoDB (djongo) and I am using mongo atlas But when I am running this command
python3 manage.py runserver
python3 manage.py makemigrations
this show this type error
pymongo.errors.OperationFailure: unsupported type in filter
But if I use my local mongod then it's works fine.
Please help me
My requirements.txt
dataclasses==0.6
dj-database-url==0.5.0
Django==2.2
django-cors-headers==3.0.1
djangorestframework==3.9.4
djongo==1.2.32
dnspython==1.16.0
pymongo==3.8.0
sqlparse==0.2.4
My Db Setting.py
DATABASES = {
'default': {
'ENGINE': 'djongo',
'NAME': 'leverrage',
'HOST': 'mongodb+srv://xxxxxxx:xxxxxxxx#cluster0-dqfd1.mongodb.net/test?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true',
'USERNAME': 'xxxxxxx',
'PASSWORD': 'xxxxxx',
'ENFORCE_SCHEMA': True,
}
}
Djongo currently is using a deprecated method from pymongo. So I decided to change my pymongo version to the 3.5.1 while djongo fix it.
#Luis Javier Palacio
How did you change the pymongo version?
PD: Can't comment on your answer because of reputation. Thats why I'm "answering" the question.
#Joaquín Gumucio
You can do it using pip like: pip install pymongo==3.5.1

django-admin dbshell raises django.core.exceptions.ImproperlyConfigured

I know this question has been asked before, but none of them worked for me so far, so I'm going to give it a chance here.
I'm trying to use MySQL as my database in django, but when I modify the settings.py and run the command:
django-admin dbshell
I get the following error:
django.core.exceptions.ImproperlyConfigured: Requested setting DATABASES,
but settings are not configured. You must either define the environment
variable DJANGO_SETTINGS_MODULE or call settings.configure()
before accessing settings.
What I did:
- I'm running windows 10.
using pipenv, I create fresh virtual environment.
install django.
start new project.
edit the settings.py
in the settings.py I change the DATABASES to the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test_db',
'USER': 'root',
'PASSWORD': '****',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
also pip installed mysqlclient
Weird thing is that when I make migrations, new tables are created, which means that DB works. why doesn't the command
django-admin dbshell
work?
based on django docs, manage.py does same thing as django-admin, and also adds settings to the sys path, therefore manage.py should be used instead of django-admin
https://docs.djangoproject.com/en/2.1/ref/django-admin/

Django to work with south requires MySQLdb

I am following the django instruction to learn django in eclipse.
I came to the part of running cmd
python manage.py migrate
and it complains about unknown command migrate.
Googled. Knew that it requires South module to be included. I downloaded/installed south, and added 'south' in the INSTALLED_APPS.
I ran the command again, this time it complains
import MySQLdb as Database
ImportError: No module named 'MySQLdb'
So I looked for MySQLdb, only to find that there is none for python 3.
I could not find anything useful. So what do you do to make django to work with mysql?
I know there're other connectors around, but I am trying to follow the django tutorial and it seems that 'migrate' cmd must use 'south' and 'south' must use MySQLdb(?)
--- update ---
Here is the DB settings in settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'test',
'USER': 'root',
'PASSWORD': '******',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I suspect 'ENGINE' has to be something else, but I failed to find enough information online to figure it out...
You can switch to any database you want MySQL or postgresql or sqlite etc for your django app. South uses the default database engine from your django setting DATABASES. As stated here
South automatically exposes the correct set of database API operations
as south.db.db; it detects which database backend you’re using from
your Django settings file.