推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
WildCat
V2EX  ›  Python

SQLAlchemy 在不同文件引用两次 Model 后提示 `[table name] is already defined for this MetaData instance`

  •  
  •   WildCat · Nov 5, 2015 · 4245 views
    This topic created in 3981 days ago, the information mentioned may be changed or developed.

    源代码在:https://github.com/imWildCat/kalecgos-docker

    我在 web_server.py 和 downloader.py 里都有引用 kalecgos.db.models ,但是提示错误。

    加了 __table_args__ = {"useexisting": True} 后则提示:

    InvalidRequestError: Multiple classes found for path "File" in the registry of this declarative base. Please use a fully module-qualified path.

    感觉都是初始化了两次, Google 了半天找不到相关问题,请问怎么解决?

    Python 新手,请多吐槽。

    5 replies  •  2015-11-05 16:29:14 +08:00
    huson
        1
    huson  
       Nov 5, 2015   ❤️ 1
    是重复载入了吧 你用了一个 import * 在 web_server
    WildCat
        2
    WildCat  
    OP
       Nov 5, 2015
    @huson 是的,那么如何解决呢,不在一个文件中 import * 也不行吗
    huson
        3
    huson  
       Nov 5, 2015   ❤️ 1
    不是已经提示你了吗 Please use a fully module-qualified path
    huson
        4
    huson  
       Nov 5, 2015   ❤️ 1
    排查下 很快就能解决了
    WildCat
        5
    WildCat  
    OP
       Nov 5, 2015 via iPhone
    @huson 现在的 path 还不够模块化吗?具体怎么写才叫模块化?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   930 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 19:43 · PVG 03:43 · LAX 12:43 · JFK 15:43
    ♥ Do have faith in what you're doing.