【问题标题】:flask sql alchemy not detecting change in table column烧瓶 sqlalchemy 未检测到表列中的更改
【发布时间】:2021-08-16 19:36:23
【问题描述】:

我在我的数据库表中添加了一个新列,我的文件夹中已经有迁移文件。所以当我尝试运行迁移时添加我的列之后它没有在数据库中创建新的列。

db init 我遇到了这个问题

Traceback (most recent call last):
  File "manage.py", line 75, in <module>
    manager.run()
  File "/usr/local/lib/python3.6/site-packages/flask_script/__init__.py", line 417, in run
    result = self.handle(argv[0], argv[1:])
  File "/usr/local/lib/python3.6/site-packages/flask_script/__init__.py", line 386, in handle
    res = handle(*args, **config)
  File "/usr/local/lib/python3.6/site-packages/flask_script/commands.py", line 216, in __call__
    return self.run(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/flask_migrate/__init__.py", line 118, in init
    command.init(config, directory, 'flask')
  File "/usr/local/lib/python3.6/site-packages/alembic/command.py", line 42, in init
    raise util.CommandError("Directory %s already exists" % directory)
alembic.util.exc.CommandError: Directory migrations already exists
 

db migrate 我收到了这个

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.
INFO  [alembic.ddl.postgresql] Detected sequence named 'enterprise_backup_id_seq' as owned by integer column 'enterprise_backup(id)', assuming SERIAL and omitting
INFO  [alembic.ddl.postgresql] Detected sequence named 'blacklist_tokens_id_seq' as owned by integer column 'blacklist_tokens(id)', assuming SERIAL and omitting
INFO  [alembic.env] No changes in schema detected.

db upgrade 我收到了这个

INFO  [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO  [alembic.runtime.migration] Will assume transactional DDL.

【问题讨论】:

  • 您是否确认该列实际上并不存在?这是一件微不足道的事情,但它让我过去了。
  • @noslenkwah 是最近添加的。 100% 肯定不存在
  • 启动新项目时只需要运行一次init;不是每次改变!您对模型所做的更改是什么?尝试添加一个显示行为的最小示例!

标签: python flask sqlalchemy


【解决方案1】:

删除迁移文件夹并从数据库中删除 alembic 版本表。然后重新启动您的进程。

这不是解决此错误的完美方法。但它会起作用。

【讨论】:

    猜你喜欢
    • 2018-12-09
    • 2019-01-04
    • 2021-06-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 2018-12-09
    • 2013-11-22
    • 1970-01-01
    相关资源
    最近更新 更多