From a0a5384e5b31ab38d6446164b519ff582982b9ec Mon Sep 17 00:00:00 2001 From: coolneng Date: Wed, 8 Jan 2020 22:40:17 +0100 Subject: [PATCH] Improve existing data check in 'export' --- code/database/export.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/database/export.py b/code/database/export.py index 98e2817..550585a 100644 --- a/code/database/export.py +++ b/code/database/export.py @@ -1,3 +1,4 @@ +from app.models import Annual_Data, Glacier, User from database.constants import DB_NAME, DB_PW, DB_USER from pandas import DataFrame, read_csv from sqlalchemy import create_engine, engine @@ -25,8 +26,10 @@ def create_dataframes() -> DataFrame: def insert_data(df_list, conn): - if conn.table_names() is not None: - return + models = [Glacier, Annual_Data, User] + for model in models: + if model.query.first() is not None: + return for key, value in df_list.items(): value.to_sql(key, con=conn, index=False, if_exists="append")