S
S
Sibastian2021-08-04 14:53:30
Python
Sibastian, 2021-08-04 14:53:30

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)


#db
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])


cursor.execute(sql, params or ())
peewee.IntegrityError: NOT NULL constraint failed: searchmodel.url

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Agagulov, 2021-08-05
@RoMoN0975

You need to set content=some_post_obj when calling Language.create()

S
Sibastian, 2021-08-09
@Sibastian

I can't figure out where to change it!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question