Steps for Django to connect to local MySQL database (pycharm)

Steps for Django to connect to local MySQL database (pycharm)

Step 1: Change DATABASES in setting.py

# Configure database DATABASES = {
  'default': {
    # A database that comes with python, which is basically not used# 'ENGINE': 'django.db.backends.sqlite3',
    # 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    # Register our own database connection 'ENGINE': 'django.db.backends.mysql', # Database engine 'NAME': 'productone', # Database name 'USER':'root', # User name for connecting to the database 'PASSWORD':'yourpassword', # User password 'HOST':'127.0.0.1', # The IP address of the host of the database to be accessed 'PORT':'3306', # Default mysql access port }
}

The second step is to enter in the console: pip install pymysql to install pymysql

insert image description here

Step 3: Add the following code to __init__.py in the project

Because I had the following problem↓, I added pymysql.version_info = (1,4,13,"final",0)

insert image description here

import pymysql
pymysql.version_info = (1,4,13,"final",0)
pymysql.install_as_MySQLdb()

Finally, you can execute the program python manage.py migrate!!! Completed

Summarize

This is the end of this article about connecting Django to a local MySQL database (pycharm). For more information about connecting Django to a local MySQL database (pycharm), please search previous articles on 123WORDPRESS.COM or continue browsing the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Detailed explanation of Django ForeignKey and database FOREIGN KEY constraints
  • How to connect Django framework to MySQL database in PyCharm
  • Django uses multiple databases
  • Django inspectdb steps to operate existing database data
  • Python web framework (django, flask) to achieve mysql database read and write separation example
  • Django solves the problem that the class in the model cannot be written to the database and the database does not have this field
  • Python's Django framework implements database queries (methods that do not return QuerySet)
  • Django database returns queryset to implement encapsulation as a dictionary
  • How to add constraints to the database in a Django project

<<:  Idea configures tomcat to start a web project graphic tutorial

>>:  Vue+Element UI realizes the encapsulation of drop-down menu

Recommend

Use of MySQL triggers

Triggers can cause other SQL code to run before o...

5 super useful open source Docker tools highly recommended

Introduction The Docker community has created man...

Operate on two columns of data as new columns in sql

As shown below: select a1,a2,a1+a2 a,a1*a2 b,a1*1...

Use the sed command to modify the kv configuration file in Linux

sed is a character stream editor under Unix, that...

Implementation of dynamic rem for mobile layout

Dynamic rem 1. First, let’s introduce the current...

How to implement scheduled backup of CentOS MySQL database

The following script is used for scheduled backup...

Will Update in a Mysql transaction lock the table?

Two cases: 1. With index 2. Without index Prerequ...

Detailed analysis of the MySQL slow log opening method and storage format

In development projects, we can monitor SQL with ...

Tic-Tac-toe game implemented in pure CSS3

Operation effect: html <div class="tic-ta...