Answer the question
In order to leave comments, you need to log in
Error cursor.execute(sql, params or ()) peewee.IntegrityError: NOT NULL constraint failed: searchmodel.url?
I'm writing a notification bot, I'm just studying databases, help me fix
the #main error
import logging
import asyncio
from aiogram import Bot, Dispatcher, executor, types, utils
from aiogram.types import ParseMode
from db import prcces_search_model, init_db, find_id_search
logging.basicConfig(level=logging.INFO)
URL = 'https://www.computeruniverse.net/ru/c/apparatnoe-obespechenie-i-komponenty/videokarty-pci-express'
TOKEN = ''
bot = Bot(token=TOKEN, parse_mode=ParseMode.HTML)
dp = Dispatcher(bot)
@dp.message_handler(commands='list')
async def sent_list(message: types.Message):
message_text = 'Строка поиска {}'.format('123')
await message.answer(text=message_text)
@dp.message_handler(commands='search')
async def send_search(message: types.Message):
search_models = find_id_search(message.chat.id)
for search_model in search_models:
await message.answer(text=search_model.title)
@dp.message_handler()
async def echo(message: types.Message):
await prcces_search_model(message)
async def scheduled(wait_for, parser):
while True:
await asyncio.sleep(wait_for)
print('parse')
pass
if name == 'main':
init_db()
loop = asyncio.get_event_loop()
loop.create_task(scheduled(10, None))
executor.start_polling(dp, skip_updates=True)
from aiogram.types import ParseMode
from aiogram import utils
from peewee import *
db = SqliteDatabase('video.db')
class BaseModel(Model):
class Meta:
database = db
class VideoCard(BaseModel):
title = CharField()
url = TextField()
class SearchModel(BaseModel):
title = CharField()
url = TextField()
def find_all_cards():
return VideoCard.select()
def find_id_search(chat_id):
return SearchModel.select().where(SearchModel.chatid == chat_id)
def find_all_search():
return SearchModel.select()
async def prcces_search_model(message):
search_exist = True
try:
search = SearchModel.select().where(SearchModel.title == message.text).get()
search.delite.instance()
await message.answer('Строка поиска удалена'.format(message.text))
return search_exist
except DoesNotExist as de:
search_exist = False
if not search_exist:
rec = SearchModel(title=message.text, chatid=message.chat.id)
rec.save()
await message.answer('Строка поиска {} добавлена'.format(message.text))
else:
await message.answer('Строка поиска {} уже есть!'.format(message.text))
return search_exist
def init_db():
db.create_tables([VideoCard, SearchModel])
Answer the question
In order to leave comments, you need to log in
You need to set content=some_post_obj when calling Language.create()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question