Django(5) Connect Django With MySQL Database

5 篇文章 0 订阅
2 篇文章 0 订阅
You can follow this article to make Django get connection with MySQL Database.

Connect Django With MySQL Database

  1. First you should launch XAMPP and open phymyadmin page. And then create a new table called “mydjango” (or any name you want).

  2. Delete the unused file called “db.sqlite3”. Django(5)_Connect_Django_With_MySQL_Database_1.png

  3. Next in settings.py file, change the DATABASE code as following.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'mydjango',
        'USER': 'root',
        'PASSWORD': '',
        'HOST': 'localhost',
        'PORT': '3316',      # you should check your own port, usually it should be '3306'
    }
}
  1. After that, in pycharm terminal, input this command python manage.py migrate. Django(5)_Connect_Django_With_MySQL_Database_2.png

  2. Until now, open mydjango database, you will see below. Django(5)_Connect_Django_With_MySQL_Database_3.png

  3. Now, when you try to get into your admin page using your password set before, you will get an error. Django(5)_Connect_Django_With_MySQL_Database_4.png

  4. To fix this, you should create a new superuser for this. So in pycharm terminal, input python manage.py createsuperuser. You can just create a new superuser with the same information as before to cover the old message. Django(5)_Connect_Django_With_MySQL_Database_5.png

  5. Finally, refresh admin page and login again. You will see this page if you get successful. Django(5)_Connect_Django_With_MySQL_Database_6.png

So far, you have connected Django with MySQL successfully. Hopefully, it helps.
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值