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