Django: get table engine from model
I'm writing a unit test to make sure my legacy database tables are using InnoDB in开发者_开发问答stead if MyISAM. Is there a way to get which engine a table is using through the model?
No, the model has no idea. You'll need to query the database directly:
>>> from django.db import connection
>>> cursor = connection.cursor()
>>> cursor.execute("SHOW TABLE STATUS WHERE name='appname_modelname'")
>>> print cursor.fetchone()
('appname_modelname',
 u'InnoDB',
 10L,
 u'Compact',
 29L,
 6779L,
 196608L,
 0L,
 49152L,
 10485760L,
 34L,
 datetime.datetime(2010, 11, 19, 13, 5),
 None,
 None,
 u'latin1_swedish_ci',
 None,
 u'',
 u'')
 加载中,请稍侯......
      
精彩评论