最新消息:20190717 VPS服务器:Vultr新加坡,WordPress主题:大前端D8,统一介绍入口:关于

【记录】Flask-Migrate升级时出现警告:Warning: Data truncated for column at row cursor.execute(statement, parameters)

Flask crifan 678浏览 0评论

之前已经把:

class Task(db.Model):
    __tablename__ = ‘tasks’
    initiatorId = db.Column(db.String(64), db.ForeignKey("users.id”))
    errandorId = db.Column(db.String(64), db.ForeignKey("users.id”))

改为:

class Task(db.Model):
    __tablename__ = ‘tasks’
    initiatorId = db.Column(db.String(64), db.ForeignKey("users.id”), default="")
    errandorId = db.Column(db.String(64), db.ForeignKey("users.id”), default=“")

然后升级成功了:

(RunningFast) ➜  staging python db_manager.py db migrate -m "add default to empty string for initiatorId and errandorId of Task"

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:113]:
app=<Flask ‘runningfast.app’>, server_port=21085, api=<flask_restful.Api object at 0x7fe5edb35310>, redis_store=<flask_redis.FlaskRedis object at 0x7fe5efdb38d0>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fe5edb35750>, sockets=<flask_sockets.Sockets object at 0x7fe5edb35ad0>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:213]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.autogenerate.compare] Detected added foreign key (errandorBillTaskId)(id) on table bills
INFO  [alembic.autogenerate.compare] Detected added foreign key (initiatorBillTaskId)(id) on table bills
INFO  [alembic.autogenerate.compare] Detected added foreign key (initiatorTaskId)(id) on table resources
INFO  [alembic.autogenerate.compare] Detected added foreign key (errandorTaskId)(id) on table resources
INFO  [alembic.autogenerate.compare] Detected added foreign key (errandorId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (errandorEndLocationId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (initiatorEndLocationId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (initiatorStartLocationId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (errandorStartLocationId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (initiatorId)(id) on table tasks
INFO  [alembic.autogenerate.compare] Detected added foreign key (task_id)(id) on table tasks_promotions
INFO  [alembic.autogenerate.compare] Detected added foreign key (promotion_id)(id) on table tasks_promotions
INFO  [alembic.autogenerate.compare] Detected added foreign key (locationId)(id) on table users
  Generating /root/RunningFast/staging/migrations/versions/98741b084631_add_default_to_empty_string_for_.py … done
(RunningFast) ➜  staging python db_manager.py db upgrade                                                                        

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:113]:
app=<Flask ‘runningfast.app’>, server_port=21085, api=<flask_restful.Api object at 0x7f45541be310>, redis_store=<flask_redis.FlaskRedis object at 0x7f455643c8d0>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7f45541be750>, sockets=<flask_sockets.Sockets object at 0x7f45541bead0>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:213]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade d48c252c778a -> 98741b084631, add default to empty string for initiatorId and errandorId of Task

现在继续去把:

class Task(db.Model):
    __tablename__ = ‘tasks’
    initiatorId = db.Column(db.String(64), db.ForeignKey("users.id”), default="")
    errandorId = db.Column(db.String(64), db.ForeignKey("users.id”), default=“")

改为:

class Task(db.Model):
    __tablename__ = ‘tasks’
    initiatorId = db.Column(db.String(64), db.ForeignKey("users.id"), nullable=False, default="")
    errandorId = db.Column(db.String(64), db.ForeignKey("users.id"), nullable=False, default=“")

然后去升级,结果有警告:

(RunningFast) ➜  staging python db_manager.py db upgrade                                                                  

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:113]:
app=<Flask ‘runningfast.app’>, server_port=21085, api=<flask_restful.Api object at 0x7fe0b01ac310>, redis_store=<flask_redis.FlaskRedis object at 0x7fe0b242a8d0>, db=<SQLAlchemy engine=’mysql://runningfast:Jiandao123@localhost/runningfast_dev’>, server_mode=staging, server_type=develop, rq=<flask_rq2.app.RQ object at 0x7fe0b01ac750>, sockets=<flask_sockets.Sockets object at 0x7fe0b01acad0>

<div–<——————————————————————————

<div–<——————————————————————————

DEBUG in app [/root/RunningFast/staging/runningfast/app.py:213]:
API_VERSION=1.0, API_URL_PREFIX=/runningfast/api/v1.0, OPEN_API_URL_PREFIX=/runningfast/api/v1.0/open

<div–<——————————————————————————

INFO  [alembic.runtime.migration] Context impl MySQLImpl.
INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
INFO  [alembic.runtime.migration] Running upgrade 98741b084631 -> 2fcd2aa96580, add nullable to False for initiatorId and errandorId of Task
/root/Envs/RunningFast/lib/python2.7/site-packages/sqlalchemy/engine/default.py:462: Warning: Data truncated for column ‘errandorId’ at row 2
  cursor.execute(statement, parameters)
/root/Envs/RunningFast/lib/python2.7/site-packages/sqlalchemy/engine/default.py:462: Warning: Data truncated for column ‘errandorId’ at row 3
  cursor.execute(statement, parameters)
。。。
/root/Envs/RunningFast/lib/python2.7/site-packages/sqlalchemy/engine/default.py:462: Warning: Data truncated for column ‘errandorId’ at row 67
  cursor.execute(statement, parameters)

不过去看数据库中字段已经生效了:

的确默认不是NULL,而是空字符串了:

所以暂时不去操心这个警告了。

转载请注明:在路上 » 【记录】Flask-Migrate升级时出现警告:Warning: Data truncated for column at row cursor.execute(statement, parameters)

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
56 queries in 0.102 seconds, using 18.91MB memory