问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/32399831/error-during-django-running-migrations-django-db-utils-operationalerror-201