Can not connect to mysql database using Django - python

I'm trying to connect my Django app with MySQL and I have Successfully installed MySQL-connector-python-2.0.4 also. But after that whenever I run server same error message is showing.
Here are my cmd ...
Here is the full message showing

you are installing MySQL connector for python (not recommended), you need the MySQLdb module, refer to this official recommendation from django doc https://docs.djangoproject.com/en/3.0/ref/databases/#mysql-db-api-drivers
and install mysqlclient it is a native driver and It’s the recommended choice.
pip install mysqlclient
for further informations have a look at this medium post : https://medium.com/#omaraamir19966/connect-django-with-mysql-database-f946d0f6f9e3

Related

Pythonanywhere Django app does not work with MySql

What do we have:
Django app hosted on Pythonanywhere with sqlite db initialized
MySql DB activated on Pythonanywhere (it provided me with db name, pasword and host - everything that I need to setup settings.py)
pip install mysqlclient finished successfully
python manage.py makemigrations - DONE
python manage.py migrate - DONE
mysql console on Pythonanywhere shows all my tables created
but restarting app causes pythonanywhere error page and link to error log
2020-08-15 17:22:56,536: Error running WSGI application
2020-08-15 17:22:56,569: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
2020-08-15 17:22:56,569: Did you install mysqlclient?
So the question is how could it be possible? As i got it right migrations are used mysqlclient to manipulate DB, how can it be not installed?
Might be someone did face with similar issue?
you need to install mysql client, but that might also throw an error, so you need to install it using its wheels from https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysqlclient and keep installing every wheel incase an error occurs.

How to run SQLAlchemy on AWS Lambda in Python

I preapre very simple file for connecting to external MySQL database server, like below:
from sqlalchemy import *
def run(event, context):
sql = create_engine('mysql://root:root#127.0.0.1/scraper?charset=utf8');
metadata = MetaData(sql)
print(sql.execute('SHOW TABLES').fetchall())
Doesn't work on AWS, but localy on Windows works perfectly.
Next, I install by pip install sqlalchemy --target my/dir and prepare ZIP file to upload packages to AWS Lambda.
Run, but with failed message No module named 'MySQLdb': ModuleNotFoundError.
Then, I use pip install mysqlclient --target my/dir, create ZIP and again upload to AWS Lambda.
Run, but with new failed message cannot import name '_mysql': ImportError.
So, what I should doing now?
SQLAlchemy includes many Dialect implementations for various backends.
Dialects for the most common databases are included with SQLAlchemy; a
handful of others require an additional install of a separate dialect.
The MySQL dialect uses mysql-python as the default DBAPI. There are
many MySQL DBAPIs available, including MySQL-connector-python and
OurSQL
Instead of mysql you may use mysql+mysqlconnector
sql = create_engine('mysql+mysqlconnector://root:root#127.0.0.1/scraper?charset=utf8')
Then use:
pip install mysql-connector --target my/dir
Create Zip and again upload to AWS Lambda.

Azure App Service ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory

On App Azure Linux with Python, the Mysql module seem not work :
2018-12-24T19:11:38.215760010Z import _mysql
2018-12-24T19:11:38.215763810Z ImportError: libmysqlclient.so.18: cannot
open shared object file: No such file or directory
...
2018-12-24T19:11:27.536810347Z django.core.exceptions.ImproperlyConfigured:
Error loading MySQLdb module.
2018-12-24T19:11:27.536813747Z Did you install mysqlclient?
requirement :
django
mysqlclient
Has anyone ever managed to run django on azure web app?
This is a common error. Using mysqlclient also requires native dependencies to be installed: either the mysql client or the mysql-compatible mariadb client. In order to address these issues the easiest way, change your project to use mysql-connector-python instead of mysqlclient. You will also have to update your settings so that any database engine that uses django.db.backends.mysql should be updated to mysql.connector.django.
It sounds like there is not mysql native client library installed in your Azure App for Linux.
Here is two cases for building custom image.
For Debian or Ubuntu image, please run apt install libmysqlclient-dev firstly to preinstall libmysqlclient.so on your Docker image.
For Fedora or CentOS iamge, please run yum install mysql-libs firstly to preinstall the same one.
Or you can directly use the existing image which has preinstalled these required libs from Azure Container Registry or DockerHub.
Please take a try that go to the app service scm site, and find the pip location, then use pip to install the required module.

Django Version 1.8.3 SQL Server v13 is not supported

I'm new to this stuff so I apologize if this is in the wrong place. I've inherited a Debian 7.14 system that has Django version 1.8.3 and Python version 2.7.6. It has a connection to SQL Server. We've just upgraded to SQL Server 2016 and are now getting the error
Exception Type: NotImplementedError
Exception Value: Sql Server v13 is not supported.
How can I upgrade to a newer version of Django for this connection to work again? What version will work with SQL Server 2016? I'm thinking it would be a good idea to upgrade Debian version as well while I'm at it, but I'm unsure whether that will break this further.
Any insight or suggestions is greatly appreciated, I've done a ton of research and I'm out of places to turn.
Most likely you're using an outdated version of Django MSSQL database connector. According to its change log, starting with v1.8 the connector support MS SQL Server 2012 and later.
In order to confirm this, check the DATABASES settings of your Django app, and see if it shows 'ENGINE': 'sqlserver_ado' as the connection type. If so,
pip install django-mssql --upgrade should fix your issue (though I haven't actually tested this).
EDIT: OK, so based on additional info from your comment ('ENGINE': 'sql_server.pyodbc' in the DATABASES settings), it looks like you're actually using django-pyodbc-azure as the database connector. This driver seems to be quite Django-version dependent. Let's first find out which version is in use:
pip show django-pyodbc-azure
The version you install should be the same as the Django version. If using Django 1.8, and if the django-pyodbc-azure version shows less than that, try installing the correct version:
pip install "django-pyodbc-azure<1.9"

How can I switch my Django project's database engine from Sqlite to MySQL?

I need help switching my database engine from sqlite to mysql. manage.py datadump is returning the same error that pops up when I try to do anything else with manage.py : ImproperlyConfigured: Error loading MySQL module, No module named MySQLdb.
This django project is a team project. I pulled new changes from bitbucket and our backend has a new configuration. This new configuration needs mysql (and not sqlite) to work. Our lead dev is sleeping right now. I need help so I can get started working again.
Edit: How will I get the data in the sqlite database file into the new MySQL Database?
According to the Database setup paragraph in Django docs:
By default, the configuration uses SQLite.
If you wish to use another database, install the appropriate database
bindings...
And Get your database running page says:
If you’re using MySQL, you’ll need the MySQL-python package, version
1.2.1p2 or higher.
To use MySQL backend you need a tool that would help Django talk to the database, an adapter.
In other words, MySQL-python (aka MySQLdb) package needs to be installed.
Try the followings steps:
1. Change DATABASES in settings.py to MYSQL engine
2. Run $ ./manage.py syncdb

Categories