Python 基于Sqlite3中的上一个条目自动递增

Python 基于Sqlite3中的上一个条目自动递增,python,sqlite,flask,Python,Sqlite,Flask,我正在创建一个基于网络的POS系统。用户单击“order submit”后,每个项目都会发送到sqlite数据库,并使用以下模式: drop table if exists orders; create table orders ( transaction_id integer primary key autoincrement, total_price integer not null, SKU integer not null, product_name te

我正在创建一个基于网络的POS系统。用户单击“order submit”后,每个项目都会发送到sqlite数据库,并使用以下模式:

drop table if exists orders;
create table orders (
    transaction_id integer primary key autoincrement,
    total_price integer not null,
    SKU integer not null,
    product_name text not null,
    unit_price integer not null,
    quantity integer not null
);
通过此代码:

@app.route('/load_ajax', methods=["GET", "POST"])
def load_ajax():
    if request.method == "POST":
        data = request.get_json()
        for group in groupby(data, itemgetter('name')):
            id, data_list = group
            for d in data_list:
                print d['subtotal']
                db = get_db()
                order = db.execute('insert into orders (total_price, SKU, product_name, unit_price, quantity) values (?, ?, ?, ?, ?)',
                [d['subtotal'], d['sku'], d['name'], d['price'], d['quantity']])
                db.commit()
        return jsonify(location=url_for('thankyou'))
当我最初创建模式时,我认为
transaction\u id integer主键autoincrement
对于一个事务id(一个附加到订单中每个项目的id)就足够了,但有点忘记了订单中可能有多个项目。所以现在,每个条目都有自己的主键,这不是我想要的。一个订单的sqlite3输出如下所示:

1|61.45|ASD|Hot Sauce|10.99|1
2|61.45|JKL|Chilli Peppers|8.99|1
3|61.45|UIO|Sip 'n' Sizzle T-Shirt|10.5|1
我希望第一列中的所有内容都是1。我可以对我的模式做些什么来获得我想要的操作吗?我不确定最好的方法是什么。

规范化数据库。 将所有重复信息放入一个表中,并将每个项目更改的所有信息放入另一个表中:

创建表格订单(
事务id整数主键自动递增,
总价整数不为空
);
创建表格订单项目(
事务\u id整数引用订单(事务\u id),
SKU整数不为空,
产品名称文本不为空,
单价整数不为空,
数量整数不为空
);

因此,我正在尝试更改我的烧瓶代码。我是否需要执行两个db.executes,或者所有这些都可以在一行上执行?