0

company_id entry box inserts data to my mysql database but it is not auto incremented, how can I turn it into auto increment?

query = "INSERT INTO basic_data(company_id, lastname, firstname, middlename) VALUES(%s, %s, %s, %s)"
cursor.execute(query, (t1.get(), t2.get(), t3.get(), t4.get()))
  • 2
    Does this answer your question? [Auto increment primary key in SQL Server Management Studio 2012](https://stackoverflow.com/questions/10991894/auto-increment-primary-key-in-sql-server-management-studio-2012) – Guy Jun 14 '21 at 12:13
  • company_id is already set to primary key in my mysql database but I don't know how to change my python script to insert an auto incremented value into the table. –  Jun 14 '21 at 12:22
  • @FlashBack the `python` script shouldn't; as the value is inserted into the table, your database should handle the auto incremented key. – artemis Jun 14 '21 at 12:35
  • @wundermahn what happens is that I still type in t1.get() entry box and it's inserted into my database as company_id, it only prevents me from having duplicate, I wish make an auto generated company_id value from t1.get() entry box without typing on it. –  Jun 14 '21 at 12:41
  • Leave `company_id` out of the `INSERT` query and it will auto increment. – Barmar Jun 14 '21 at 12:54
  • Don't use the `t1.get` value, let the DB assign the value. – Barmar Jun 14 '21 at 12:55

0 Answers0