Spindle thermal error is a major factor affecting the machining accuracy of machine tools. The time-consuming experiments required to model the thermal error of each machine tool spindle makes exhaustive studies difficult. Therefore, it is critically important to develop a transferable spindle thermal error prediction model that ensures robustness and accuracy, which provides theoretical guidance for the thermal error compensation and accuracy improvement of different machine tools. To achieve this, this paper proposes a migratory prediction method based on spatial-temporal axial attention bidirectional long short-term memory (Axial Attention-BiLSTM) network to predict the thermal error of computer numerical control (CNC) machine tool spindles under varying working conditions. By analyzing the mechanism of spindle thermal error generation, the spindle system is divided into multiple temperature regions, and the importance of each region is automatically determined by using the Spatial Attention mechanism. At the same time, considering the historical dependence of thermal error, BiLSTM is used to fuse the previous and following time series information and determine the weights of different time steps by Temporal Attention mechanism to strengthen the times series memory of thermal error prediction. An Axial Attention-BiLSTM model for thermal error prediction is built based on the spindle test bench. Compared with the BiLSTM and long short-term memory (LSTM) models, this model shows better and more stable prediction performance when migrated to various working conditions of horizontal CNC grinding machines.