Django Project in Pycharm connection to MySQL database

Source: Internet
Author: User

First, install Pycharm and Django not detailed said, self-Baidu

Second, the new Django project also did not say

Third, configure Django to connect to MySQL

1.models.py write a class that inherits Models.model

class Book (models. Model):    name=models. Charfield (max_length=) Price    =models. Integerfield ()    pub_date=models. Datefield ()
View Code

2. Modify the settings.py file

DATABASES = {    'default': {        'ENGINE':'Django.db.backends.mysql',         'NAME':'Books', #你的数据库名称'USER':'Root', #你的数据库用户名'PASSWORD':"', #你的数据库密码'HOST':"', #你的数据库主机, leave blank default to localhost'PORT':'3306', #你的数据库端口}} Copy Code
View Code

3. Modify the __init__.py file under the project folder

Do not install Pymsql (python3), install it on Pycharm, add the following after installation

Import pymysqlpymysql.install_as_mysqldb ()

4. Start

[email protected] django_orm]# python manage.py makemigrations
[email protected] django_orm]# python manage.py migrate


5. Configure the connection

Finally enter the account password login

Django Project in Pycharm connection to MySQL database

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.