改掉系統默認的sqlite3數據庫,
# Database
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
DATABASES = {
'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
'ENGINE': 'django.db.backends.mysql',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'NAME':'djangoDB',
'USER':'root',
'PASSWORD':'123456',
'port':'3306',
}
}
然后啟動報錯,
ImportError: No module named 'MySQLdb'
據說要裝MySQL-python
可是MySQL-python一直無法安裝成功。
又報錯ImportError: No module named 'ConfigParser'
因為python3中叫做configparser,是小寫。
好吧,聽說不用MySQL-python可以用pymsql代替,然后就趕緊下載pip install pymysql
然后再啟動,還是不行啊,還是ImportError: No module named 'MySQLdb'
百度了下,看這篇文章http://www.jianshu.com/p/82781add8449
加了之后就好了。
這里說下MySQL-python吧。
MySQL-python的解釋看官方說法
MySQLdb is an interface to the popular MySQL database server for Python. The design goals are:
- Compliance with Python database API version 2.0 [PEP-0249]
- Thread-safety
- Thread-friendliness (threads will not block each other)
MySQL-3.23 through 5.5 and Python-2.4 through 2.7 are currently supported. Python-3.0 will be supported in a future release. PyPy is supported.
說白了就是連接mysql的python接口,有了他就可以用python來操作數據庫了。類似java的JDBC那一套東西把。