Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to fix MySQL-Connector INSERT Bug?

I’m trying to get my user id and write it into mysql db.
The problem occurs at the moment when I try to write this data (31-34). It writes random id into db (2147483647), but i need to write my user id (1003694956919148625). Any ideas?

class MyModal(discord.ui.Modal):
    def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self.add_item(discord.ui.InputText(label="Name"))
        self.add_item(discord.ui.InputText(label="Gender"))
        self.add_item(discord.ui.InputText(label="City"))
        self.add_item(discord.ui.InputText(label="Description", style=discord.InputTextStyle.long))

    async def callback(self, interaction: discord.Interaction):
        id = interaction.user.id
        print(id)
        cursor = connection.cursor()
        cursor.execute(
            "INSERT INTO users (id, name, gender, city, description) VALUES (%s, %s, %s, %s, %s)",
            (id, self.children[0].value, self.children[1].value, self.children[2].value, self.children[3].value)
        )
        connection.commit()

In console print id is correct
But in db – it isn’t

I tried to print id in console – it works
I tried to save id in MySQL – in not works

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Which type are you using for the id in the db?

I recommend you to store it in an varchar or text column. Otherside, there can be problems with the type or overflow of the value

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading