Django“运行迁移”时出错:django.db.utils.OperationalError:(2013,“在查询期间失去与MySQL服务器的连接”) [英] Error during Django "Running migrations": django.db.utils.OperationalError: (2013, 'Lost connection to MySQL server during query')

查看:3758
本文介绍了Django“运行迁移”时出错:django.db.utils.OperationalError:(2013,“在查询期间失去与MySQL服务器的连接”)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Django项目连接到远程MySQL数据库。



在Django中创建了所有模型类之后,我尝试了

  python manage.py makemigrations 

一切好的然后我进入

  python manage.py migrate 

然后在运行迁移:,应用event.0002_auto_20150904_2141 ...中出现错误



错误代码: / p>

  django.db.utils.OperationalError:(2013,在查询期间与MySQL服务器的连接失败)

有谁知道可能会导致此错误?我遵循官方Django教程中的确切程序。

解决方案

请执行以下操作:

1-安装新的mySQL服务器首先。

2-创建新的数据库

3-配置django设置如下:

  DATABASES = {
'default':{
'ENGINE':'django.db.backends.mysql',
'NAME' 'db_name',
'USER':'root',
'PASSWORD':'db_pass',
'HOST':'localhost',#或您的数据库托管的IP地址on
'PORT':'3306',
'OPTIONS':{init_command:SET storage_engine = MyISAM},
}

4-重新运行syncdb

5-重新运行迁移

希望这个工作


My Django project is connect to the remote MySQL database.

After I created all the model classes in Django, I tried

python manage.py makemigrations

Everything is fine. Then I entered

python manage.py migrate

Then an error occurred during "Running migrations:", "Applying event.0002_auto_20150904_2141..."

Error code:

django.db.utils.OperationalError: (2013, 'Lost connection to MySQL server during query')

Does anyone know what might cause this error? I followed the exact procedures in the official Django tutorial.

解决方案

Please do this :
1- Install new fresh of mySQL server first.
2- Create new db
3- Config in django settings like this :

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'db_name',
    'USER': 'root',
    'PASSWORD': 'db_pass',
    'HOST': 'localhost',   # Or an IP Address that your DB is hosted on
    'PORT': '3306',
    'OPTIONS': {"init_command": "SET storage_engine=MyISAM"},
}

4- Re-run syncdb
5- Re-run migrate
I hope this work

这篇关于Django“运行迁移”时出错:django.db.utils.OperationalError:(2013,“在查询期间失去与MySQL服务器的连接”)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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