错误关系“ demographic_types”不存在是什么意思?

时间:2019-11-29 07:03:50

标签: python postgresql

我正在尝试截断pgsql数据库中的数据,然后尝试从csv文件插入数据,下面的代码能够截断数据,但是尝试复制时失败,并出现以下错误

  

“ OUT错误代码:42P01。错误错误:关系“ demographic_types”不存在“

for fle in sorted(glob.glob(os.path.join(path,"database/data/*.csv"))):
print ('>>>Migrating data %s' % fle)
table_name = os.path.basename(fle).replace('.csv', '')

    try:
        #silent_query(conn, sql, None)
        with conn.cursor() as cur:
        #delete data first
        print('Deleting data from table  %s' % table_name)
        cur.execute('TRUNCATE %s CASCADE' % table_name)

        with open(fle, 'r') as f:
        #headers = ", ".join(table_column_mapping_data[table_name])
        print("i am here open")
        sql = "COPY %s from STDIN WITH CSV HEADER DELIMITER AS ','" % table_name
        print(sql)
        cur.copy_expert(sql, f)
        conn.commit()
        except Exception as exp:
        print ('Error Code: %s. Error %s' % (exp.pgcode, exp.pgerror))

我该如何解决该错误?

0 个答案:

没有答案