yetone
V2EX  ›  问与答

在web应用的开发过程中,想在数据库中增加一个字段并初始化,该怎样做?

  •  
  •   yetone · Jun 23, 2012 · 3909 views
    This topic created in 5146 days ago, the information mentioned may be changed or developed.
    我最近的Flask项目,数据库用的是Flask-SQLAlchemy和MySQL。在开发过程中,一直有个问题让我十分纠结,那就是在开发过程中突然想给一个表增加个字段,该怎么做?
    比如,今晚我想给topic这个表增加last_reply_date这个字段,用于记录最后一次评论的时间,但是我实现该功能后不知道如何对数据库下手,对已有的topic改怎样初始化?
    1 replies    1970-01-01 08:00:00 +08:00
    shinwood
        1
    shinwood  
       Jun 23, 2012
    直接MySQL里面ALTER TABLE 或者用phpMyadmin 来实现即可,至于初始化数据,可以写一个小的文件批量把这个字段更新一下,更新的条件为:

    1. 如果已有回复,那么最后回复时间等于最后回复的时间;
    2. 如果没有回复,那么最后回复时间等于帖子发布时间。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   891 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 19:43 · PVG 03:43 · LAX 12:43 · JFK 15:43
    ♥ Do have faith in what you're doing.