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

Steps to create a Vite project

Table of contents Preface What does yarn create d...

How to create an Nginx server with Docker

Operating environment: MAC Docker version: Docker...

Detailed explanation of Vue filters

<body> <div id="root"> <...

JS implements simple calendar effect

This article shares the specific code of JS to ac...

Web form creation skills

In fact, the three tables above all have three ro...

The pitfall record of case when judging NULL value in MySQL

Table of contents Preface Mysql case when syntax:...

vite2.x implements on-demand loading of ant-design-vue@next components

1. Use version vite:2.0 ant-design-vue: 2.0.0-rc....

How to use border-image to implement text bubble border sample code

During the development activity, I encountered a ...

Tutorial on installing JDK Tomcat MySQL on Linux (remote access using Mac)

One environment Alibaba Cloud Server: CentOS 7.4 ...

Detailed explanation of the steps to create a web server with node.js

Preface It is very simple to create a server in n...

The process of building and configuring the Git environment in Docker

Configure Git environment in Docker At work, I en...