我正在尝试从脚本中的数据库中的表中删除一行。也许这不是最简单的方法,但我认为它应该是可能的。我正在尝试以下操作:
from stemewebapp import app
from stemewebapp.models import Job, db
import sys
#
# Check arguments
#
if len(sys.argv) != 2:
print 'USAGE: %s <job uuid>' % (sys.argv[0])
sys.exit(-1)
job_uuid = sys.argv[1]
#
# Do everything in context
#
with app.test_request_context():
#
# Get job
#
query = db.session.query(Job).filter_by(uuid=job_uuid)
#query = Job.query.filter_by(uuid=job_uuid)
if 1 != query.count():
raise RuntimeError('Got more than one job by UUID.')
#
# Delete from database
#
db.session.delete(query.first())
db.session.commit()
我收到以下错误:
OperationalError: (OperationalError) no such table: job u'SELECT count(*) AS count_1 \nFROM (SELECT job.id AS job_id, job.creation_date AS job_creation_date, job.name AS job_name, job.uuid AS job_uuid, job.pid AS job_pid, job.completed AS job_completed \nFROM job \nWHERE job.uuid = ?) AS anon_1' ('743d952f-9cfc-4efc-bfa5-58da67c4a131',)