При написании небольшой программы для контроля базы данных на SQLite3 и PyWebIO возникает данная ошибка:
Traceback (most recent call last):
File "C:\Users\WORK\AppData\Local\Programs\Python\Python310\lib\site-packages\pywebio\session\coroutinebased.py", line 321, in step
coro_yield = self.coro.send(result)
File "C:\Users\WORK\AppData\Local\Programs\Python\Python310\lib\site-packages\pywebio\session\coroutinebased.py", line 101, in _start_main_task
await target()
File "C:\Users\WORK\Desktop\SQLite\main.py", line 20, in main
cursor.execute("CREATE TABLE IF NOT EXISTS users ('id' INTERGER PRIMARY KEY AUTOINCREMENT, 'name' STRING)")
sqlite3.OperationalError: AUTOINCREMENT is only allowed on an INTEGER PRIMARY KEY
Вот код:
import sqlite3 as sql
import asyncio
from pywebio import start_server
from pywebio.input import *
from pywebio.output import *
from pywebio.session import defer_call, info as session_info
global name
name = ""
async def main():
put_markdown("Users database control.")
database = put_scope(name="database")
put_scrollable(database, height=300, keep_bottom=True)
with sql.connect('Users.db') as db:
cursor = db.cursor()
cursor.execute("CREATE TABLE IF NOT EXISTS users ('id' INTERGER PRIMARY KEY AUTOINCREMENT, 'name' STRING)")
def add():
global name
cursor.execute("SELECT name FROM users")
cursor.execute("INSERT OR IGNORE INTO users ('name') VALUES (?)",(name))
clear("database")
cursor.execute("SELECT * FROM USERS")
rows = cursor.fetchall()
[put_text(f'{row[0]} {row[1]}', scope="database") for row in rows]
toast(f"Sucessfully added {name}")
def delete():
global name
cursor.execute("SELECT name FROM users")
cursor.execute("DELETE FROM users WHERE name = ?",(name))
clear("database")
cursor.execute("SELECT * FROM USERS")
rows = cursor.fetchall()
[put_text(f'{row[0]} {row[1]}', scope="database") for row in rows]
toast(f"Sucessfully deleted {name}")
def exit():
toast("See you next time!")
db.commit()
cursor.close()
quit()
def clr():
global next_id
cursor.execute("DELETE FROM users")
next_id = 0
toast("Sucessfully cleared database")
clear("database")
global name
put_button("Add user", onclick=add)
put_button("Delete user", onclick=delete)
put_button("Clear database", onclick=clr)
put_button("Exit", onclick=exit)
while True:
clear("database")
cursor.execute("SELECT * FROM USERS")
rows = cursor.fetchall()
[put_text(f'{row[0]} {row[1]}', scope="database") for row in rows]
name = await input("Username", placeholder="Username")
put_button("Exit", onclick=exit)
if __name__ == '__main__':
start_server(main, port=8080, debug=True)