Answer the question
In order to leave comments, you need to log in
How to fix sqlite3.IntegrityError: NOT NULL constraint failed?
from RXConfigBase import bot, logger
from RXSQLConfig import sqlite3, user_id, name, surname, patronymic
#Начало, логиниться и регистрация
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.from_user.id, 'Добро пожаловать!\n' f'♂️>> {message.chat.first_name}|{message.chat.last_name} <<♀️\n\n' 'Входа в систему /log\n' 'Регистрация /reg')
#Регистрация
@bot.message_handler(commands=['reg'])
def start_message(message):
bot.send_message(message.from_user.id, 'Регистрацию аккаунта.\nНачнём?(Напиши "next")')
bot.register_next_step_handler(message, name)
#Собираем данные для регистрации и БД
def name(message): #получаем имя
bot.send_message(message.from_user.id, 'Укажите имя')
global name
global user_id
user_id = message.from_user.id
name = message.text
conn = sqlite3.connect("DataBase/RXDataBase.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO Profile (user_id, name) VALUES (?, ?)", (user_id, name, ))
#cursor.execute(f"SELECT get_user_id FROM Profile WHERE id = {message.from_user.id}")
#cursor.execute(f"SELECT get_name FROM Profile WHERE id = {message.text}")
bot.register_next_step_handler(message, surname)
def surname(message): #получаем фамилии
bot.send_message(message.from_user.id, 'Укажите фамилию')
global surname
surname = message.text
conn = sqlite3.connect("DataBase/RXDataBase.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO Profile (surname) VALUES (?)", (surname, ))
bot.register_next_step_handler(message, patronymic)
def patronymic(message): #получаем отчества
bot.send_message(message.from_user.id, 'Укажите отчество')
global patronymic
patronymic = message.text
conn = sqlite3.connect("DataBase/RXDataBase.db")
cursor = conn.cursor()
cursor.execute("INSERT INTO Profile (patronymic) VALUES (?)", (patronymic, ))
return
if __name__ == '__main__':
bot.polling(none_stop=True, interval=0)
Error:
cursor.execute("INSERT INTO Profile (user_id, name) VALUES (?, ?)", (user_id, name))
sqlite3.IntegrityError: NOT NULL constraint failed: Profile.surname
Answer the question
In order to leave comments, you need to log in
sqlite3.IntegrityError: NOT NULL constraint failed: Profile.surname
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question