getting error when i changed database sqllite3 to mysql

40 views
Skip to first unread message

Gulsher Khan

unread,
Oct 5, 2019, 9:37:11 PM10/5/19
to Django users
I trying to change default database(sqllite) which is given by the Django. I want to use mysql database. I put lots of effort but nothing went well. I successfully has been install mysql, mysqlclient, mysql-connector whatever i have read in the documentation. 

I'm using OS: Ubuntu 19.04
Screenshot from 2019-10-06 01-12-52.png
Screenshot from 2019-10-06 01-14-32.png

Gil Obradors

unread,
Oct 5, 2019, 10:33:51 PM10/5/19
to django...@googlegroups.com

Missatge de Gulsher Khan <gulsher...@gmail.com> del dia ds., 5 d’oct. 2019 a les 23:36:
I trying to change default database(sqllite) which is given by the Django. I want to use mysql database. I put lots of effort but nothing went well. I successfully has been install mysql, mysqlclient, mysql-connector whatever i have read in the documentation. 

I'm using OS: Ubuntu 19.04

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ea48f010-5ea5-4d58-9033-2e83a3e1de06%40googlegroups.com.

Aldian Fazrihady

unread,
Oct 5, 2019, 11:17:48 PM10/5/19
to django...@googlegroups.com
Have you created the database on MySQL? 

On Sun, Oct 6, 2019 at 4:36 AM Gulsher Khan <gulsher...@gmail.com> wrote:
I trying to change default database(sqllite) which is given by the Django. I want to use mysql database. I put lots of effort but nothing went well. I successfully has been install mysql, mysqlclient, mysql-connector whatever i have read in the documentation. 

I'm using OS: Ubuntu 19.04

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ea48f010-5ea5-4d58-9033-2e83a3e1de06%40googlegroups.com.


--
Regards,

Motaz Hejaze

unread,
Oct 6, 2019, 12:02:15 AM10/6/19
to django...@googlegroups.com
If you have data , export it to csv , then after creating the mysql database populate it with data ftom csv file

Desh Deepak

unread,
Oct 6, 2019, 6:57:48 AM10/6/19
to django...@googlegroups.com
pip install pymysql

And then, 

setting.py
import pymysql


pymysql.install_as_MySqldb()


And edit

DATABASE: = {
                'default' :{
           'ENGINE': 'django.db.backends.mysql',
'NAME': 'database name',
'USER': 'username',
'PASSWORD': 'password',
'HOST' : 'localhost',
'PORT' : '3306',
         }
}


You need to create database before run migrate command...


Joseph Emeka

unread,
Oct 6, 2019, 1:07:43 PM10/6/19
to django...@googlegroups.com
I think you need to create the database "django" on you database  back-end. And try making migrations again. 

On Sat, Oct 5, 2019, 22:36 Gulsher Khan <gulsher...@gmail.com> wrote:
I trying to change default database(sqllite) which is given by the Django. I want to use mysql database. I put lots of effort but nothing went well. I successfully has been install mysql, mysqlclient, mysql-connector whatever i have read in the documentation. 

I'm using OS: Ubuntu 19.04

--

Dick in Texas

unread,
Oct 6, 2019, 9:54:50 PM10/6/19
to Django users
I have tried to use a new, empty database, but that did not work.  Still got the question if I have installed MySQLclient.

Tried the statements from Desh Deepak.  The install and import went well.  However, when I tried to migrate, I got the message:  module 'pymysql' has no attribute 'install_as_MySqldb'.  I put this statement directly below the import statement.


Below is some of my additional background info that may help.

i am begining a django project and want to use MySQL instead of SQLlite.  So, I watched a video to learn how to use MySQL with Python.  VBased on that, I was able to install MySQL into a C:\MySQL directory successfully.  I also created a database with userid(root) and password.  Then I wrote a Python program that read in a CSV file, created a table in the same database and then INSERTed the rows into the table.  Also needed to 'import mysql.connector'.  Using SQL Workbench, I was able to verify that all was successful. 
Next I tried to access this database from Django without success.  Here's what I did.  First I created a virtual environment and then activated it.  Next, ran 'django-admin startproject <kprojectr name> .  This created the settings file, but it is set up for SQLlite.  I edited this file to change these parameters:
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'gammon',
        'USER':'root',
        'PASSWORD':'1ltarty#',

        'HOST': 'localhost',
        'PORT': '3306',
I skip the 'migrate' step.  Next was 'python manage.py runserver. This failed.  I got many error message which I saved in a text file.  At the beginning of the messages MySQLdb could not be imported as it couldn't be found.  Neat the end of the errors, there is a message asking if I had insjtalled mysqlclient.
I have researched these two errors without much success.  I tried to install MySQLclient, but always get a message that the requirement was already satisfied.  I cannot find any module MySQLdb anywhere on  my PC.  I think these two areas are related.  Since I am able to use MySQL with vanilla Python successfully, I suspect I have a PATH error perhaps.
I am now at a loss as to what I might try next.  Does anyone have any ideas?  All comments appreciated.

Dick in Texas

unread,
Oct 6, 2019, 10:48:46 PM10/6/19
to Django users
I just got by the ' 'install_as_MySqldb' error.  SQL needed to be in upper case.  Now, got new error.  
new error:  mysqlclient 1.3.13 or newer is required; you have 0.9.3.  Does it ever end?

Tosin Ayoola

unread,
Oct 7, 2019, 3:30:51 PM10/7/19
to django...@googlegroups.com
Hello in your settings.py files,  you still have,  sqlite3 as your db engine instead of MySQL so probably try changing that then see if it's works 

On Oct 5, 2019 22:35, "Gulsher Khan" <gulsher...@gmail.com> wrote:
I trying to change default database(sqllite) which is given by the Django. I want to use mysql database. I put lots of effort but nothing went well. I successfully has been install mysql, mysqlclient, mysql-connector whatever i have read in the documentation. 

I'm using OS: Ubuntu 19.04

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.

Desh Deepak

unread,
Oct 8, 2019, 3:45:47 AM10/8/19
to django...@googlegroups.com
You can't use above version of django 2.0 with pymysql.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d4b3ffa0-cab7-473e-8615-993b4aac4609%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages