Issue
I have a sqlite query written in python: dibbs5.py
cursor.executemany ( """
INSERT INTO dibbs_spider_dibbs_fields(hash,nsn,nomenclature,technical_documents,solicitation,
status,purchase_request,issued,return_by,file)
VALUES (?,?,?,?,?,?,?,?,?,?)
""" , records )
This works fine in local, in production when I execute this from terminal, it executes. But when I schedule this in cronjob, it shows the error:
cursor.executemany ( """
sqlite3.OperationalError: no such table: dibbs_spider_dibbs_fields
There is a table name dibbs_spider_dibbs_fields
Crontab:
31 09 * * * /usr/bin/python3 /root/spider/manage.py makemigrations > /root/spider/migration.log 2>&1
32 09 * * * /usr/bin/python3 /root/spider/manage.py migrate > /root/spider/migration2.log 2>&1
33 09 * * * DISPLAY=:0 /usr/bin/python3 /root/spider/dibbs5.py > /root/spider/dibbserorr3.log 2>&1
Solution
Did you run the dibbs5.py
using root
in the production terminal? Does it work? If Yes, please change the crontab using this command
sudo crontab -u root -e
31 09 * * * /usr/bin/python3 /root/spider/manage.py makemigrations > /root/spider/migration.log 2>&1
32 09 * * * /usr/bin/python3 /root/spider/manage.py migrate > /root/spider/migration2.log 2>&1
33 09 * * * DISPLAY=:0 /usr/bin/python3 /root/spider/dibbs5.py > /root/spider/dibbserorr3.log 2>&1
I have a feeling that you are not editing crontab for root
. The program that you encountered is because the table is absent from the file as environmental variable(s) were not correct setup, resulting in accessing wrong file.
Answered By - yoonghm Answer Checked By - Cary Denson (WPSolving Admin)