client_obj = Client.objects.create(name='client1')
status = create_database('client1')
def create_database('client1'):
con = None
dbname = 'client1'
con = connect(dbname='postgres', user='***', host =
'localhost', password='***')
con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
cur = con.cursor()
cur.execute("SELECT 1 FROM pg_catalog.pg_database WHERE
datname = '{}' ".format(dbname))
exists = cur.fetchone()
if not exists:
cur.execute('CREATE DATABASE ' + dbname)
print "DATABASE NOT EXISTS"
else:
print "DATABASE EXISTS"
cur.close()
con.close()
创建数据库后,如何使迁移自动化?或者有其他方法来实现这一点吗?你知道吗
相关问题 更多 >
编程相关推荐