'Getting bytes written to SQL database for integer column, want integer to be written

I am writing data from a dash app to a SQL database setup by Django and then reading back the table in a callback. I have a column that the value should either be 1 or 2 but the value is as below in the SQL database:

SQL Database view of column that should contain 1 or 2

When this is read back to a pandas dataframe it appears as b'\00x\01x... or something along those lines, which then gets read wrong when it needs to be used.

The django code for the column is:

selected = models.IntegerField(default=1, null=True)

I am writing and reading the data using SQLAlchemy. Number appeared perfectly in pandas dataframe before involving SQL. Read and write code:

select = pd.read_sql_table('temp_sel', con=engine)

select.to_sql('temp_sel', con=engine, if_exists='append', index=False)

Any help would be appreciated.



Solution 1:[1]

Solved by specifying the variable as an integer before sending to SQL as follows:

j = int(j)

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 Gareth Simons