如何在pythonanywhere上设置Django MySQL Database? [英] How to set up Django MySQL Database on pythonanywhere?

查看:139
本文介绍了如何在pythonanywhere上设置Django MySQL Database?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我第一次使用MySQL而不是SQLite3部署站点,因此,在阅读一些文档后,我发现我必须更改一些类似文件:

It's the first time I'm deploying a site using MySQL instead of SQLite3, so I'm quite new at this, after reading some documentation I found out that I have to change some files like this :

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_site_db',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': '?', #currently using pythonanywhere (not on localhost)           
        'PORT': '?',  
    }
}

manage.py

try:
    import pymysql
    pymysql.install_as_MySQLdb()
except:
    pass

(PyMySQL == 0.7.10,Django 1.9,Python 3.5)

当我使用python manage.py migrate运行Bash控制台时,出现此错误消息:

When I run the Bash Console using python manage.py migrate I get this error message :

django.db.utils.OperationalError:(2003年,无法连接到'localhost'上的MySQL服务器([Errno 111]连接被拒绝)")

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

我认为它与数据库配置中的HOSTPORT有关,我不知道该添加些什么,它与MySQL,PythonAnywhere甚至我自己的数据库有关领域 ?如何解决此问题并使用Django 3.5正确设置MySQL?

I thought it has something to do with the HOST and the PORT from the Database configurations, I don't know what I should add in these, does it have to do with MySQL, PythonAnywhere or even my own domain ? How can I resolve this problem and set up MySQL correctly with Django 3.5 ?

推荐答案

检查指导.我用它来部署我的Web应用程序.

Check this guide. I used it to deploy my webapp.

这篇关于如何在pythonanywhere上设置Django MySQL Database?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆