Answer the question
In order to leave comments, you need to log in
sqlite3.OperationalError: table USER has no column named status how to fix?
import sqlite3
import json
import time
import logging
from NSystem_config import bot
from NSystem_config import get_name, get_surname, get_otchestvo, get_phone, get_year, get_inf_profil
from NSystem_keyboard import keyboard_osnova, keyboard_nazad
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Первый старт + подключение клавиатуры
@bot.message_handler(commands=['start'])
def send_welcome(message):
con = sqlite3.connect("dannie_2.db")
cur = con.cursor()
cur.execute(f"SELECT count(user_id) FROM USER WHERE user_id = {message.chat.id}")
if cur.fetchone()[0] == 0:
con.commit()
bot.send_message(message.from_user.id, f"Здравствуйте! Вас приветствует чат-бот, бот создан для удобного информирования граждан и взаимодействия между Администрацией, муниципальным учреждением и население. Заполните анкету для дальнейшего использования !") #reply_markup=markup_inline_soglashenie
# Добавляем пользователю данные
id = message.chat.id
name = (f"{message.chat.first_name} {'|'} {message.chat.last_name}")
status = 0
balance = 0
last_popolnenie = 0
referals = 0
ref_balance = 0
con = sqlite3.connect("dannie_2.db")
cur = con.cursor()
cur.execute(f"INSERT INTO USER ('id','name','status','balance','last_popolnenie','referals', 'ref_balance') "
f'VALUES ("{id}", "{name}", "{status}", "{balance}", "{last_popolnenie}", "{referals}", "{ref_balance}")')
else:
con.commit()
name = get_name(message)
surname = get_surname(message)
otchestvo = get_otchestvo(message)
phone = get_phone(message)
year = get_year(message)
inf_profil = get_inf_profil(name, surname, otchestvo, phone, year)
bot.send_message(message.from_user.id, f"Привет, {message.chat.first_name}! \n\n\n{inf_profil}",
reply_markup=keyboard_osnova())
# Работа бота
@bot.message_handler(content_types="text")
def get_text_message(message):
con = sqlite3.connect("dannie_2.db")
cur = con.cursor()
name = get_name(message)
surname = get_surname(message)
otchestvo = get_otchestvo(message)
phone = get_phone(message)
year = get_year(message)
inf_profil = get_inf_profil(name, surname, otchestvo, phone, year)
if message.text == "Профиль":
bot.send_message(message.from_user.id, "Отправьте любое сообщение, чтобы продолжить")
bot.register_next_step_handler(message, inf_profil)
elif message.text == "Обратная связь":
bot.send_message(message.from_user.id, "В разработке",
reply_markup=keyboard_nazad())
elif message.text == "Инструкция по использованию":
bot.send_message(message.from_user.id, "В разработке",
reply_markup=keyboard_nazad())
elif message.text == "Назад":
bot.send_message(message.from_user.id, " Вы вернулись в главное меню", reply_markup=keyboard_osnova())
if __name__ == '__main__':
bot.polling(none_stop=True)
After adding to the database writes
File "C:\Users\Centu\Desktop\NSystem DB\NSystem_bot.py", line 58, in get_text_message
name = get_name(message)
File "C:\Users\Centu\Desktop\NSystem DB\NSystem_config.py", line 14, in get_name
name = cur.fetchone()[0]
TypeError: 'NoneType' object is not subscriptable
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question