I'm new to Django. It wasted me whole afternoon to config the MySQL engine. I am very confused about the database engine and the database driver. Is the engine also the driver? All the tutorial said that the ENGINE should be 'django.db.backends.mysql', but how the ENGINE decide which driver is used to connect MySQL?
Every time it says 'django.db.backends.mysql', sadly I can't install MySQLDb and mysqlclient, but PyMysql and the official mysql connector 2.1.3 has been installed. How could I set the driver to PyMysql or mysql connector?
Many thanks!
OS: OS X Al Capitan
Python: 3.5
Django: 1.9
This question is not yet solved:
Is the ENGINE also the DRIVER?
You can import pymsql so it presents as MySQLdb. You'll need to do this before any django code is run, so put this in your manage.py file
import pymysql
pymysql.install_as_MySQLdb()
The short answer is no they are not the same.
The engine, in a Django context, is in reference to RDBMS technology. The driver is the library developed to facilitate communication to that actual technology when up and running. Letting Django know what engine to use tells it how to translate the ORM functions from a backend perspective. The developer doesn't see a change in ORM code but Django will know how to convert those actions to a language the technology understands. The driver then takes those actions (e.g. selects, updates, deletes) and sends them over to a running instance to facilitate the action.
Related
I want to use MySQL in flask, and one config is
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql+pymysql://user:password#127.0.0.1:3306/db"
If I use mysql+pymysql, it can work
But when I only use mysql, the erroe message like this
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
But in my code, I don't import pymysql, so what is the pymysql and why need use that can work
I know pymysql is a moudle
Thanks your reply!
The create_engine function (which is what uses the URL given in the config), requires you to give it a "dialect". A "dialect" is the name of the underlying database engine that SQLAlchemy is connecting to.
However, since many databases have multiple different clients (in Python these implement DBAPI), so in many cases (such as for the mysql dialect) you're required to give the name of the client you want SQLAlchemy to use. In this case, you're asking it to use the pymysql library to actually handle connectivity with MySQL.
SQLAlchemy 1.3 supports the following dialect/DBAPI-libraries for connecting to MySQL:
mysqlclient (maintained fork of MySQL-Python)
PyMySQL
MySQL Connector/Python
CyMySQL
OurSQL
Google Cloud SQL
PyODBC
zxjdbc for Jython
I use SQLite3 in python because my school computers don't allow us to install anything to python so I used the pre installed SQLite3 module.
I'm working on a program whose back end relies on an SQLite3 database, however the databases are created and stored on their computer.
Is it possible for me to "Host" an SQLite3 database on let's say a server and allow my script to access them remotely (my script could edit the database from my school computer)?
By the way, I'm using python 3.X
EDIT
i made a database api that runs in python 3, its called TaliffDb
to install type pip3 install TaliffDB in your terminal. im working on a documentation, but please do comment if you have any questions
Write an API on the remote server, yes. This could be hosted by a web framework of your choice.
You won't get a direct network connection to a file
I am writing a small web application using Flask and I have to use DynamoDB as backend for some hard requirements.
I went through the tutorial on Flask website without establishing sqlite connection. All data were pulled directly from DynamoDB and it seemed to work.
Since I am new to web development in general and Flask framework, do you see any problems with this approach?
No. SQLite is just one option for backend storage. SQLite is mentioned in the tutorial only for its simplicity in getting something working fast and simply on a typical local developers environment. (No db to or service to install/configure etc.)
I have a website on an Australian webhost. I have designed my website to allow people to login & their login details are stored in an SQLite3 database. I interact with the SQLite3 database using pythons SQLite3 module(found only in python2.5 & up)
My Problem: the webhost runs Python 2.4 so I cannot communicate with(query or modify) my SQLite3 database. The webhost will not allow me to install my own version of python or upload modules unless I upgrade to VPS.
What do you think are my options to still be able to work/interface with my SQL database? Do you know of way to interact with a SQL database using python modules from Python 2.4 or earlier?
Do you know of a python 2.4 module that will let me interact with an SQL database(can be MySQL, SQLite, etc.)?
There is a Python MySQL Module, called MySQLDB, which supports Python 2.3-2.7: http://sourceforge.net/projects/mysql-python/
The User Guide can be found here: http://mysql-python.sourceforge.net/MySQLdb.html
Check out pysqlite. It is the same module as in the newer python versions and I have used it no prob in 2.4 before.
I have a standard django setup using postgres, but I also want to access data from a mssql database. I have installed pyodbc and was in the process of installing django-pyodbc but the instructions tell me how to make the mssql the default database which is not what I want.
I was hoping somebody could point me in the right direction. It doesnt bother me if the method bypasses django and just uses Python to retrieve the data
Cheers,
JJ
If you're using Django 1.2 or later, you can use Django's built-in multi-database support. You can follow the django-pyodbc directions, and give your database a name other than 'default'.