django中动态新建postgres数据库表

import psycopg2

def create_new_table(table_id):
conn = psycopg2.connect(database='Test', user='postgres', password='123456', host='127.0.0.1', port='5432')
cur = conn.cursor()
print('aaaaa')
cur.execute('''CREATE TABLE DataFile%s
(nid INT PRIMARY KEY NOT NULL,
create_time DATE NOT NULL,
message_head TEXT,
message_body_data bytea,
message_body_param TEXT);''' % table_id)

print("Table created successfully")

conn.commit()
conn.close()
 
posted @ 2019-12-02 09:31  一只小羊  阅读(723)  评论(0编辑  收藏  举报