Django配置mysql資料庫
阿新 • • 發佈:2018-11-10
1.在專案setting.py配置資訊中
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'perfectcrm',
'USER': 'root',
'PASSWORD': 'welcome123',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
2.在modules.py,完善需要建立的表
3.輸入指令python manage.py makemigrations
4.輸入指令python manage.py migrate
注意:
1.如果modules.py中包含text/boolean欄位,資料庫可能會報錯 [The used table type doesn't support BLOB/TEXT columns]
解決方法:
開啟mysql的配置檔案找到my.ini檔案
# The default storage engine that will be used when create new tables when
default-storage-engine = MEMORY
改為
# The default storage engine that will be used when create new tables when default-storage-engine = MyISAM
在命令視窗執行net stop mysql 關閉服務,在執行net start mysql 重啟服務
2.在修改後再重新執行python manage.py migrate 會報錯,因為之前的操作已經進行了一部分
解決方法
輸入python manage.py migrate --fake