简体   繁体   English

如何删除sqlalchemy列上的自动更新?

[英]How can I remove an autoupdate on sqlalchemy Column?

When updating two other column values, the created column, which remains untouched on my code, updates to the current time by itself. 当更新其他两个列的值时,创建的列(其在我的代码中保持不变)会自行更新为当前时间。

This is the Model 这是模型

class Query(db.Model):
    __tablename__ = "query"
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(2000))
    created = db.Column(db.DateTime)
    modified = db.Column(db.DateTime)
    launched = db.Column(db.Integer)
    exception = db.Column(db.String(500), nullable=True)
    enable = db.Column(db.Boolean)
    expired = db.Column(db.Boolean)
    app_id = db.Column(db.String(20))
    app_secret = db.Column(db.String(40))
    page_id = db.Column(db.String(20))
    token = db.Column(db.String(300))

updating code 更新代码

query.launched = query.launched + 1
query.modified = until
db.session.commit()

What I expected is the modified column to be updated to the 'until' time, which already happens, but the created column to stay untouched. 我期望的是修改后的列将更新为“直到”时间,这种情况已经发生,但是创建的列保持不变。

I got the error. 我得到了错误。 It was in my sql syntax. 这是我的SQL语法。 I still didn't figure out why did it happen, but it was resolved by changing this: 我仍然不知道为什么会发生,但是通过更改此方法解决了:

- created TIMESTAMP NOT NULL - created时间戳不为空

+ created TIMESTAMP DEFAULT CURRENT_TIMESTAMP + created TIMESTAMP DEFAULT CURRENT_TIMESTAMP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM