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 install cuda10.1 on Ubuntu 20.04 (graphic tutorial)

Pre-installation preparation The main purpose of ...

Example of how to install kong gateway in docker

1. Create a Docker network docker network create ...

jQuery plugin to achieve carousel effect

A jQuery plugin every day - jQuery plugin to impl...

XHTML Getting Started Tutorial: Form Tags

<br />Forms are an important channel for use...

8 Reasons Why You Should Use Xfce Desktop Environment for Linux

For several reasons (including curiosity), I star...

A brief analysis of SQL examples for finding uncommitted transactions in MySQL

A long time ago, I summarized a blog post titled ...

Detailed explanation of WeChat Mini Program official face verification

The mini program collected user personal informat...

How to implement controllable dotted line with CSS

Preface Using css to generate dotted lines is a p...

Detailed explanation of TypeScript 2.0 marked union types

Table of contents Constructing payment methods us...

Node uses koa2 to implement a simple JWT authentication method

Introduction to JWT What is JWT The full name is ...

How to insert pictures into HTML pages and add map index examples

1. Image formats supported on the WEB: GIF: can s...