'SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'temp_left_1' already exists

Getting this error while calling the stored procedure in laravel controller

 $sql = DB::select(DB::raw("CALL whole_x_count('".$node."',@count_750 ,@count_1500 ,@count_3000 ,
                                                              @count_t_750 ,@count_t_1500 ,@count_t_3000 ,
                                                              @count_p_750 ,@count_p_1500 ,@count_p_3000,
                                                              @count_c_1  ,@count_c_2 ,@count_c_3,
                                                              @count_c_4  ,@count_c_5 ,@count_c_6)" ));

this is how am calling the procedure

getting this error

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'temp_left_1' already exists (SQL: CALL whole_x_count('jk001',@count_750 ,@count_1500 ,@count_3000 , @count_t_750 ,@count_t_1500 ,@count_t_3000 , @count_p_750 ,@count_p_1500 ,@count_p_3000, @count_c_1 ,@count_c_2 ,@count_c_3, @count_c_4 ,@count_c_5 ,@count_c_6))


Solution 1:[1]

This is not a problem with Laravel, but with its procedures that are trying to create a table that already exists. As I see it appears to be a temporary table. An alternative (without change any code in the existing procedures) is to execute a command to delete this temporary table before running this SQL command.

DB::raw("DROP TABLE IF EXISTS temp_left_1");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adriano dos Santos Junior