由于外键只支持innodb,故必须让默认的表引擎为innodb
1.可通过修改mysql的设置,在my.cnf 添加一行 default-storage-engine=INNODB,重启引擎,这样mysql <<show engines
就可以看到默认引擎为INNODE了。
2.设置django的project的setting.py里面的database相关的设置,如下:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', '
sqlite3' or 'oracle'.
'OPTIONS':{
'init_command':'SET storage_engine=INNODB',
},
'NAME': 'mydb', # Or path to database file if using sqlite3.
'USER': 'mmog', # Not used with sqlite3.
'PASSWORD': 'mmog', # Not used with sqlite3.
'HOST': '/data/mysqldata/mysql.sock', # Set to empty string for localh
ost. Not used with sqlite3.
'PORT': '', # Set to empty string for default. Not used with sqlite3.
}
}