首页 > 技术文章 > django中动态新建postgres数据库表

yangyangming 2019-12-02 09:31 原文

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()
 

推荐阅读