I am attempting to use a corporate SQL Server as the backend for my Django project with Python 3.5.2. I have installed Django 2.0.3, pyodbc==4.0.22, django-pyodbc-azure 2.0.3, pypiwin32==219 (pip freeze below). I have also configured DATABASES in my site's settings.py (see below). When attempting to run the server I get the following error: No module named 'sql_server'. I referenced other questions, the most relevant of which appeared to be: No module named sql_server.pyodbc.base, which concluded that the django-pyodbc-azure and Django versions needed to be identical. This did not solve my problem, however; the same error persists.
Traceback (most recent call last):
File "manage.py", line 24, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\K5SH\venv\lib\site-packages\django\core\management\__init__.py"
, line 338, in execute_from_command_line
utility.execute()
File "C:\Users\K5SH\venv\lib\site-packages\django\core\management\__init__.py"
, line 312, in execute
django.setup()
File "C:\Users\K5SH\venv\lib\site-packages\django\__init__.py", line 18, in se
tup
apps.populate(settings.INSTALLED_APPS)
File "C:\Users\K5SH\venv\lib\site-packages\django\apps\registry.py", line 108,
in populate
app_config.import_models(all_models)
File "C:\Users\K5SH\venv\lib\site-packages\django\apps\config.py", line 198, i
n import_models
self.models_module = import_module(models_module_name)
File "C:\Users\K5SH\AppData\Local\Programs\Python\Python35-32\lib\importlib\__
init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 665, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "C:\Users\K5SH\venv\lib\site-packages\django\contrib\auth\models.py", lin
e 41, in <module>
class Permission(models.Model):
File "C:\Users\K5SH\venv\lib\site-packages\django\db\models\base.py", line 139
, in __new__
new_class.add_to_class('_meta', Options(meta, **kwargs))
File "C:\Users\K5SH\venv\lib\site-packages\django\db\models\base.py", line 324
, in add_to_class
value.contribute_to_class(cls, name)
File "C:\Users\K5SH\venv\lib\site-packages\django\db\models\options.py", line
250, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length(
))
File "C:\Users\K5SH\venv\lib\site-packages\django\db\__init__.py", line 36, in
__getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "C:\Users\K5SH\venv\lib\site-packages\django\db\utils.py", line 240, in _
_getitem__
backend = load_backend(db['ENGINE'])
File "C:\Users\K5SH\venv\lib\site-packages\django\db\utils.py", line 129, in l
oad_backend
raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'sql_server.pyodbc' isn't an availa
ble database backend.
Try using 'django.db.backends.XXX', where XXX is one of:
'base', 'mysql', 'oracle', 'postgresql_psycopg2', 'sqlite3'
Error was: No module named 'sql_server'
Installed packages:
chardet==2.3.0
configparser==3.5.0
cycler==0.10.0
diff-match-patch==20121119
Django==2.0.3
django-crispy-forms==1.7.2
django-csvimport==2.4
django-debug-toolbar==1.9.1
django-import-export==1.0.0
django-money==0.9.1
django-mssql==1.8
django-pyodbc-azure==2.0.3.0
djangorestframework==3.6.3
et-xmlfile==1.0.1
jdcal==1.3
matplotlib==1.5.3
mysqlclient==1.3.12
numpy==1.11.2rc1+mkl
openpyxl==2.4.8
pandas==0.18.1
psycopg2==2.7.3.2
pymssql==2.1.2
pyodbc==4.0.22
pyparsing==2.1.9
pypiwin32==219
pypyodbc==1.3.3
python-dateutil==2.5.3
pytz==2016.6.1
scipy==0.18.1
seaborn==0.7.1
six==1.10.0
sqlalchemy==1.1.4
sqlparse==0.2.4
tablib==0.10.0
virtualenv==15.0.3
xlrd==1.0.0
xlwt==1.2.0
Databases:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'NAME': 'my_db_name',
'USER': '',
'PASSWORD': '',
'HOST': 'my_sql_host',
'PORT': '',
'OPTIONS': {
'driver': 'ODBC Driver 13 for SQL Server',
},
},
}
(Note: I have attempted this both with and without the 'OPTIONS' setting).
I started fresh on Windows using Python 3.6.0 and virtualenv 15.1.0. These should be close enough that this should work.
First I created and activated a virtualenv, and installed django-pyodbc-azure, which in turn installed Django and pyodbc as dependencies:
virtalenv djangowin
djangowin\Scripts\activate.bat
pip install django-pyodbc-azure
Then I started a fresh Django project:
django-admin startproject sqltest
Then I edited sqltest\sqltest\settings.py and updated my DATABASES definition to use a freshly created database:
DATABASES = {
'default': {
'ENGINE': 'sql_server.pyodbc',
'HOST': 'cdw-sql0101.wharton.upenn.edu',
'PORT': '1433',
'NAME': 'flipperpa',
'USER': 'flipperpa',
'PASSWORD': '',
'AUTOCOMMIT': True,
'OPTIONS': {
'driver': 'SQL Server',
'unicode_results': True,
'host_is_server': True,
},
}
}
...and it worked like a charm:
(djangowin) C:\Users\tallen\sqltest>python manage.py runserver
Performing system checks...
System check identified no issues (0 silenced).
March 23, 2018 - 16:39:51
Django version 2.0.3, using settings 'sqltest.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.
Is there some step along this path that didn't work for you? Are you sure your virtualenv is active? The command djangowin\Scripts\activate.bat is very important - you're going to do that each time you open a new terminal window.
Default virtual environment doesn't work properly on azure. Activate command seems has no effect. But if you create your own virtual environment on azure it works properly.
I faced the same kind of problem for my project then I installed virtual environment for myself and edited the auto deployment configurations scripts. Now it is working perfectly.
I found this issue mainly due to Version of django I replaced my Django version with django==2.1.15 then it worked.
django-pyodbc-azure==2.1.0.0
pyodbc=4.0
Related
I'm trying to deploy my Django app in Heroku. I'm also using PostGreSQL and Github. I've been using a bunch of random tutorials to set this up and try to debug the results, so I apologize if there are "inconsistencies".
When I run git push heroku main, I get the error remote: KeyError: 'psql' Error while running '$ python manage.py collectstatic --noinput:
Here's the traceback.
remote: -----> $ python manage.py collectstatic --noinput
remote: Traceback (most recent call last):
remote: File "/tmp/build_e87847fa/manage.py", line 22, in <module>
remote: main()
remote: File "/tmp/build_e87847fa/manage.py", line 18, in main
remote: execute_from_command_line(sys.argv)
remote: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
remote: utility.execute()
remote: File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 363, in execute
remote: settings.INSTALLED_APPS
remote: File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 82, in __getattr__
remote: self._setup(name)
remote: File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 69, in _setup
remote: self._wrapped = Settings(settings_module)
remote: File "/app/.heroku/python/lib/python3.9/site-packages/django/conf/__init__.py", line 170, in __init__
remote: mod = importlib.import_module(self.SETTINGS_MODULE)
remote: File "/app/.heroku/python/lib/python3.9/importlib/__init__.py", line 127, in import_module
remote: return _bootstrap._gcd_import(name[level:], package, level)
remote: File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
remote: File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
remote: File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
remote: File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
remote: File "<frozen importlib._bootstrap_external>", line 790, in exec_module
remote: File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
remote: File "/tmp/build_e87847fa/medrec_project/settings.py", line 106, in <module>
remote: DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
remote: File "/app/.heroku/python/lib/python3.9/site-packages/dj_database_url.py", line 55, in config
remote: config = parse(s, engine, conn_max_age, ssl_require)
remote: File "/app/.heroku/python/lib/python3.9/site-packages/dj_database_url.py", line 103, in parse
remote: engine = SCHEMES[url.scheme] if engine is None else engine
remote: KeyError: 'psql'
remote:
remote: ! Error while running '$ python manage.py collectstatic --noinput'.
remote: See traceback above for details.
This is what I think is relevant from my settings file:
import os
import django_heroku
import dj_database_url
import psycopg2
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.getenv('DB_NAME'),
'USER': os.getenv('DB_USER'),
'PASSWORD':os.getenv('DB_PASS'),
'HOST': 'localhost',
'PORT':'5432',
}
}
DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
django_heroku.settings(locals())
The only place in my code that has psql is in my .env file:
SECRET_KEY='<mysecretkey>'
DATABASE_URL='psql://urser:un-githubbedpassword#127.0.0.1:8458/database'
SQLITE_URL='sqlite:///my-local-sqlite.db'
CACHE_URL='memcache://127.0.0.1:11211,127.0.0.1:11212,127.0.0.1:11213'
REDIS_URL='rediscache://127.0.0.1:6379/1?client_class=django_redis.client.DefaultClient&password=ungithubbed-secret'
DB_NAME='medrecapp'
DB_USER='<myusername>'
DB_PASS='<mypassword>'
DB_HOST='127.0.0.1'
When I run py manage.py collectstatic everything runs fine.
As far as I can tell, I've added PostGreSQL to PATH (points to the bin folder of PostGreSql).
I can use psql in my terminal without any problems
I can push changes to git without issues.
I've updated my Heroku Settings Config Vars with everything from my .env file.
Does anyone know how to solve this?
Thanks!
The solution is to change the address for postgres in the .env from 'psql://...' to 'pgsql://...'
in your case will be something like
DATABASE_URL='pgsql://urser:un-githubbedpassword#127.0.0.1:8458/database'
Knowing why it is happening is not necesary for this to work, but if you are interested... This is happening because dj_database_url at some point select the engine for the database based on the first word of DATABASE_URL.
Checking the SCHEMAS array we can see
{'postgres': 'django.db.backends.postgresql_psycopg2', 'postgresql': 'django.db.backends.postgresql_psycopg2', 'pgsql': 'django.db.backends.postgresql_psycopg2', 'postgis': 'django.contrib.gis.db.backends.postgis', 'mysql': 'django.db.backends.mysql', 'mysql2': 'django.db.backends.mysql', 'mysqlgis': 'django.contrib.gis.db.backends.mysql', 'mysql-connector': 'mysql.connector.django', 'mssql': 'sql_server.pyodbc', 'spatialite': 'django.contrib.gis.db.backends.spatialite', 'sqlite': 'django.db.backends.sqlite3', 'oracle': 'django.db.backends.oracle', 'oraclegis': 'django.contrib.gis.db.backends.oracle', 'redshift': 'django_redshift_backend'}
they had entries for 'postgres', 'pgsql' and 'postgresql' but no for 'psql', that's why we got the 'KeyError' error.
I am using Django3 and Python3 with the latest version to learn Django.
I want to use an existing sqlite3 database for my django project. But I have problems while I was using the migrate command.
I have done very few steps to my project so far:
1. use the venv, upgrade pip, install django,
2. generate a project,
3. insert an app, and add it into INSTALLED_APPS,
4. In the settings.py, I added the existing database into the DATABASES as follows.
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
},
'testdb': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'TestDB.sqlite3'),
},
}
Then I use the method as here shows, to generate the models.py file.
Using existing database in Django
The generated models.py looks like: (where I added the max_length=25)
from django.db import models
class Stars(models.Model):
actorname = models.CharField(db_column='ActorName', blank=True, null=True, max_length=25)
realname = models.CharField(db_column='RealName', blank=True, null=True, max_length=25)
class Meta:
managed = False
db_table = 'Stars'
6. Then I run python manage.py migrate and/or python manage.py makemigrations, here I see the following errors:
(venv) PS D:\Workfolder_Web\testProject\backend\project> python .\manage.py migrate
Traceback (most recent call last):
File ".\manage.py", line 21, in <module>
main()
File ".\manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
utility.execute()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\core\management\__init__.py", line 377, in execute
django.setup()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\registry.py", line 114, in populate
app_config.import_models()
File "D:\Workfolder_Web\testProject\backend\venv\lib\site-packages\django\apps\config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 779, in exec_module
File "<frozen importlib._bootstrap_external>", line 916, in get_code
File "<frozen importlib._bootstrap_external>", line 846, in source_to_code
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
ValueError: source code string cannot contain null bytes
7. My database TestDB.sqlite3 is very simple, it looks like:
Question: How could I debug it? I am not using any bootstrap, urls, views or routers in my current codes.
Thanks for the help!
If you changed the Models you either add a default value for the new fields or remove the database.
I have been going through the Django tutorial in the following link. I have completed this on a Mac, however I am hitting problems on windows 10:
djangoproject
In Tutorial part 2, when it comes to creating a new superuser, it fails.
If I run the following on a Mac, I can create a new superuser. It fails when I run a similar command on windows.
I have tried running both of the following on windows:
source venv/bin/activate
python manage.py createsuperuser
and
.\venv\Scripts\activate
py manage.py createsuperuser
Package (pip list):
Package Version
----------- -------
Django 2.2.6
docutils 0.15.2
pip 19.3.1
pycodestyle 2.5.0
pytz 2019.3
setuptools 41.4.0
sqlparse 0.3.0
wheel 0.33.6
The db.sqlite3 database is present, and as far as I can tell has a reasonable structure (there are lots of Django specific tables).
I expect to create a new superuser, but instead get this output:
Traceback (most recent call last):
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\password_validation.py", line 26, in get_password_validators
klass = import_string(validator['NAME'])
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\utils\module_loading.py", line 17, in import_string
module = import_module(module_path)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'django.contrib.auth.password_validation '
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "manage.py", line 21, in <module>
main()
File "manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
utility.execute()
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\core\management\base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 61, in execute
return super().execute(*args, **options)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\core\management\base.py", line 364, in execute
output = self.handle(*args, **options)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 132, in handle
validate_password(password2, self.UserModel(**fake_user_data))
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\password_validation.py", line 44, in validate_password
password_validators = get_default_password_validators()
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\password_validation.py", line 19, in get_default_password_validators
return get_password_validators(settings.AUTH_PASSWORD_VALIDATORS)
File "C:\Users\Mark\Documents\Development\Python\PYTHON---DJANGO---TUTORIAL\venv\lib\site-packages\django\contrib\auth\password_validation.py", line 29, in get_password_validators
raise ImproperlyConfigured(msg % validator['NAME'])
django.core.exceptions.ImproperlyConfigured: The module in NAME could not be imported: django.contrib.auth.password_validation .UserAttributeSimilarityValidator. Check your AUTH_PASSWORD_VALIDATORS setting.
As suspected, the problem is in your password validation configuration, in the way you've set up those line continuations using backslashes.
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation\
.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation\
.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation\
.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation\
.NumericPasswordValidator',
},
]
evaluates to
[
{'NAME': 'django.contrib.auth.password_validation .UserAttributeSimilarityValidator'},
{'NAME': 'django.contrib.auth.password_validation .MinimumLengthValidator'},
{'NAME': 'django.contrib.auth.password_validation .CommonPasswordValidator'},
{'NAME': 'django.contrib.auth.password_validation .NumericPasswordValidator'}
]
and there's no such module as django/contrib/auth/password_validation .py.
If the same code works on macOS, then... okay, weird, could be a filename normalization thing, but still, that's the problem.
The fix, naturally, is to change that to
AUTH_PASSWORD_VALIDATORS = [
{'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator'},
{'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator'},
{'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator'},
{'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator'},
]
or if you'd like to have those line continuations,
AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation."
"UserAttributeSimilarityValidator"
},
{
"NAME": "django.contrib.auth.password_validation."
"MinimumLengthValidator"
},
{
"NAME": "django.contrib.auth.password_validation."
"CommonPasswordValidator"
},
{
"NAME": "django.contrib.auth.password_validation."
"NumericPasswordValidator"
},
]
– that is, string literals back to back, implicitly concatenating them – is also valid, even if, in my opinion, less readable.
I'm setting GitHub source ↓
https://github.com/priyankavergadia/Django-Dialogflow-GoogleVisionAPI
But I have trouble in [Deploy the app to the App Engine standard environment] phase.
At a glance Deploying have been done well.But I'm trying to access webservice, so [502 Bad Gateway] appears.
At local environment(running python manage.py runserver), this program works well.
Please give me some advices.
My environment:
Windows10
Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32
django 2.2.4
MySQL second generation 5.7
mysql django
I serched and tried to:
install mysqlclient and uninstall PyMySQL
rewrite [import ~]part in various pattern...
description in Django setting.py below
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# Install PyMySQL as mysqlclient/MySQLdb to use Django's mysqlclient adapter
# See https://docs.djangoproject.com/en/2.1/ref/databases/#mysql-db-api-drivers
# for more information
import MySQLdb as sql# noqa: 402
# [START db_setup]
if os.getenv('GAE_APPLICATION', None):
# Running on production App Engine, so connect to Google Cloud SQL using
# the unix socket at /cloudsql/<your-cloudsql-connection string>
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/michatbot-250809:us-central1:polls-instance2',
'USER': 'test',
'PASSWORD': '',
'NAME': 'polls',
}
}
else:
# Running locally so connect to either a local MySQL instance or connect to
# Cloud SQL via the proxy. To start the proxy via command line:
# $ cloud_sql_proxy -instances=[INSTANCE_CONNECTION_NAME]=tcp:3306
#
# See https://cloud.google.com/sql/docs/mysql-connect-proxy
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '127.0.0.1',
'PORT': '3306',
'NAME': 'polls',
'USER': 'test',
'PASSWORD': '',
}
}
# [END db_setup]
eroor log on Google App Engine below
textPayload: "Traceback (most recent call last):
File "/env/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
worker.init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/gthread.py", line 104, in init_process
super(ThreadWorker, self).init_process()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 129, in init_process
self.load_wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
self.wsgi = self.app.wsgi()
File "/env/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
return self.load_wsgiapp()
File "/env/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
return util.import_app(self.app_uri)
File "/env/lib/python3.7/site-packages/gunicorn/util.py", line 350, in import_app
__import__(module)
File "/srv/main.py", line 1, in <module>
from mysite.wsgi import application
File "/srv/mysite/wsgi.py", line 16, in <module>
application = get_wsgi_application()
File "/env/lib/python3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
django.setup(set_prefix=False)
File "/env/lib/python3.7/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 57, in __getattr__
self._setup(name)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/env/lib/python3.7/site-packages/django/conf/__init__.py", line 107, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/python3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/srv/mysite/settings.py", line 82, in <module>
import MySQLdb as sql # noqa: 402
ModuleNotFoundError: No module named 'MySQLdb'"
There are two threads where the community figured out several ways to solve this error depending on your SO and software's versions. You can refer to these threads, second one, and also to this one that addresses discussion more about connecting MySQL in Python 3 on Windows.
Make sure to follow the documentation about Python 3.7 in the GAE Standard. Also, GAE has some specific support for using Django, I'd suggest going through the Django Support documentation and Django App example.
I changed databases from mysql to postgre. Since there was no data in teh db yet, I just deleted the migrations folders for each of the apps. When I ran makemigrations afterwards though, I got this error:
/theme/admin.py", line 2, in <module>
from models import theme, theme_file
ImportError: No module named 'models'
Everything worked fine before, nothing changed in the code other than the migrations folders being cleaned.
Any ideas?
/Users/jl/.virtualenvs/bolts3/bin/python /Users/jl/Desktop/Bolts/manage.py runserver 8000
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x108e15ae8>
Traceback (most recent call last):
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 113, in inner_run
autoreload.raise_last_exception()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 249, in raise_last_exception
six.reraise(*_exception)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(*args, **kwargs)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/apps/registry.py", line 115, in populate
app_config.ready()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready
self.module.autodiscover()
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
autodiscover_modules('admin', register_to=site)
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
import_module('%s.%s' % (app_config.name, module_to_search))
File "/Users/jl/.virtualenvs/bolts3/lib/python3.5/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 986, in _gcd_import
File "<frozen importlib._bootstrap>", line 969, in _find_and_load
File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "/Users/jl/Desktop/Bolts/theme/admin.py", line 2, in <module>
from models import theme, theme_file
ImportError: No module named 'models'
Just deleting the migrations will not fix the issue when you change database types. In your settings.py file, you must change the default database settings to point to your new PostgreSQL database, and also specify the schema, db user and password etc. Perhaps you haven't done this?
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'mydatabase',
'USER': 'mydatabaseuser',
'PASSWORD': 'mypassword',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
See: https://docs.djangoproject.com/en/1.10/ref/settings/
Mmmm it would seem like you deleted a __init__.py file by accident?
Remember that a folder must have such file to be a python module, and when a folder it's a python module you can import from it.