diff --git a/freqtrade/persistence/migrations.py b/freqtrade/persistence/migrations.py index e96f83caa..9f7ab29cd 100644 --- a/freqtrade/persistence/migrations.py +++ b/freqtrade/persistence/migrations.py @@ -98,7 +98,10 @@ def migrate_trades_and_orders_table( with engine.begin() as connection: # drop indexes on backup table in new session for index in inspector.get_indexes(trade_back_name): - connection.execute(text(f"drop index {index['name']}")) + if engine.name == 'mysql': + connection.execute(text(f"drop index {index['name']} on {trade_back_name}")) + else: + connection.execute(text(f"drop index {index['name']}")) order_id, trade_id = get_last_sequence_ids(engine, trade_back_name, order_back_name) @@ -198,7 +201,8 @@ def check_migrate(engine, decl_base, previous_tables) -> None: # Check if migration necessary # Migrates both trades and orders table! if not has_column(cols, 'buy_tag'): - logger.info(f'Running database migration for trades - backup: {table_back_name}') + logger.info(f"Running database migration for trades - " + f"backup: {table_back_name}, {order_table_bak_name}") migrate_trades_and_orders_table( decl_base, inspector, engine, table_back_name, cols, order_table_bak_name) # Reread columns - the above recreated the table! diff --git a/tests/test_persistence.py b/tests/test_persistence.py index d98238f6f..b239f6d70 100644 --- a/tests/test_persistence.py +++ b/tests/test_persistence.py @@ -600,7 +600,8 @@ def test_migrate_new(mocker, default_conf, fee, caplog): assert trade.stoploss_last_update is None assert log_has("trying trades_bak1", caplog) assert log_has("trying trades_bak2", caplog) - assert log_has("Running database migration for trades - backup: trades_bak2", caplog) + assert log_has("Running database migration for trades - backup: trades_bak2, orders_bak0", + caplog) assert trade.open_trade_value == trade._calc_open_trade_value() assert trade.close_profit_abs is None @@ -733,7 +734,7 @@ def test_migrate_mid_state(mocker, default_conf, fee, caplog): assert trade.initial_stop_loss == 0.0 assert trade.open_trade_value == trade._calc_open_trade_value() assert log_has("trying trades_bak0", caplog) - assert log_has("Running database migration for trades - backup: trades_bak0", caplog) + assert log_has("Running database migration for trades - backup: trades_bak0, orders_bak0", caplog) def test_adjust_stop_loss(fee):