DateTime creation time, modification time, default,server_default,onupdate in Flask-sqlalchemy

Source: Internet
Author: User


Record the first time created, default


Falsk the following two fields


CREATE_TIME1 = db. Column (db. DateTime, default== db. Column (db. DateTime, Default=datetime.now ())


The difference between the two:



The first insert is expected, the data insertion time, each data inserted can be automatically based on the current time generation



The second is a fixed time, the program deployment time, all the data is this fixed time



In fact, the default value is not reflected in the MySQL database, which is sqlalchemy when inserting data.



If you want to have default values in the generated table, use Server_default


Name = db. Column (db. String (server_default=' hh')


Because the MySQL datetime type data does not support functions, it is not able to specify the default value bit current time


Record the time of each modification, OnUpdate
Update_time = db. Column (db. DateTime, Default=datetime.now,onupdate=datetime.now)





DateTime creation time, modification time, default,server_default,onupdate in Flask-sqlalchemy


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.