old_contents: #-*- coding:utf-8 -*-
  import asyncio
  import aiomysql
  from tools.config import Config
  
  
  class AutoCreate(object):
  	def __init__(self):
  		pass
  	def run(self):
  		pass
  class MysqlAutoCreate(AutoCreate):
  	def __init__(self,model,config):
  		self._config=config
  		self._table=model.__table__
  		self._fields=model.__columns__
  		self._sql='create tables `%s` ('%self._table
  	@asyncio.coroutine
  	def _create_connection(self):
  		type(self)._conn=yield from aiomysql.connect(db=self._config['database'],
  								user=self._config['user'],
  								host=self._config['host'],
  								password=self._config['password'])						
  	def _create_field_type(self):
  		pass
  @asyncio.coroutine
  def auto_create():
  	conn=yield from aiomysql.connect(db=Config.database.database,
  					host=Config.database.host,
  					password=Config.database.password,
  					user=Config.database.user)
  	cursor =yield from conn.cursor()
  	yield from cursor.execute('use xx;')
  	ret=yield from cursor.fetchall()
  	print(ret)
  
  if __name__=='__main__':
  	loop=asyncio.get_event_loop()
  	loop.run_until_complete(asyncio.wait([auto_create()]))
  	loop.close()
  
  	
  
  
  
new_contents: #-*- coding:utf-8 -*-
  
  from tools.config import Config
  import logging
  logging.basicConfig(level=logging.ERROR)
  from app.models import *
  try:
  	import MySQLdb
  except ImportError:
  	logging.error("can't import 'MySQLdb' module")
  
  class AutoCreate(object):
  	def __init__(self):
  		pass
  	def run(self):
  		pass
  
  class MysqlAutoCreate(AutoCreate):
  	def __new__(cls,*args,**kw):
  		if not hasattr(cls,'_instance'):
  			cls._instance=super().__new__(cls)
  		return cls._instance
  	def __init__(self,model):
  		self._table=model.__table__
  		self._fields=model.__columns__
  		if not hasattr(type(self),'_conn'):
  			type(self)._conn=MySQLdb.connect(db=Config.database.database,
  						user=Config.database.user,
  						host=Config.database.host,
  						passwd=Config.database.password)
  		self._sql=''
  	def _create_table_sql(self):
  		self._sql='CREATE TABLE `%s` ('%self._table
  		for field_name,field in self._fields.items():
  			self._sql+=' `%s` '%field_name
  			self._sql+=field['type']
  			if field['constraints']['primary_key']:
  				self._sql+=' PRIMARY KEY'
  			if field['constraints']['auto_increment']:
  				self._sql+=' AUTO_INCREMENT'
  			if field['constraints']['unique_key']:
  				self._sql+=' UNIQUE KEY'
  			if field['constraints']['null']:
  				self._sql+=' NOT NULL '
  			if field['constraints']['default']:
  				self._sql+=' default "'+str(field['constraints']['default'])+'"'
  			self._sql+=', '
  		self._sql=self._sql[:self._sql.rindex(',')]
  		self._sql+=' ) charset utf8;'
  		return self._sql
  	def run(self):
  		self._create_table_sql()
  		cursor=type(self)._conn.cursor()
  		cursor.execute(self._sql)
  		cursor.close()
  		type(self)._conn.commit()
  
  if __name__=='__main__':
  	auto=MysqlAutoCreate(User())
  	#print(auto._create_table_sql())
  	auto.run()
  
  	
  
  
  
subject: change mysql driver 'aiomysql' to 'mysqlclient'