connect mysql database with django

0

Hi, I have my project done in django but I did it using a tutorial that used sqlite3 but I already have my database created and mysql and I want to connect, I modify the settings.py but I do not know what else to modify it: / I only have a single table called marks with the fields id, name, address, lat, lng, and type the same that I use and show in my application could someone guide me? I do not find much information about it since all of them do the database of 0 or use sqlite3 that I do not understand I leave my code in case you want to take a look HERE , thank you very much in advance

    
asked by Naoto 05.11.2017 в 00:23
source

2 answers

0

For mysql if I'm not mistaken you have several options in question of libraries to make the connection, I use sqlparse == 0.1.19 and my connection configuration to the database is as follows:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydatabase',
        'USER': 'root',
        'PASSWORD': 'password',
        'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
        'PORT': '3306',
        'STORAGE_ENGINE': 'INNODB'
    }
}

So first install using pip sqlparse, and then in your settings.py change the variable DATABASES which is the way to connect to your database (you must have previously created the mydatabase database).

Greetings!

    
answered by 05.11.2017 / 01:25
source
0

You have to create in your phpmyadmin a bd with the same name as your bd in the settings.py and then go to your project through your console and type python manage.py makemigrations The next python manage.py migrate

And everything would be fine.

    
answered by 08.11.2017 в 13:48