开发者

Django: get table engine from model

开发者 https://www.devze.com 2023-02-05 13:06 出处:网络
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 h

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'')
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号