V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 2015-11-05 15:08:30 +08:00 · 3629 次点击
    这是一个创建于 3112 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    我在 web_server.pydownloader.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 条回复    2015-11-05 16:29:14 +08:00
    huson
        1
    huson  
       2015-11-05 16:18:42 +08:00   ❤️ 1
    是重复载入了吧 你用了一个 import * 在 web_server
    WildCat
        2
    WildCat  
    OP
       2015-11-05 16:20:31 +08:00
    @huson 是的,那么如何解决呢,不在一个文件中 import * 也不行吗
    huson
        3
    huson  
       2015-11-05 16:24:22 +08:00   ❤️ 1
    不是已经提示你了吗 Please use a fully module-qualified path
    huson
        4
    huson  
       2015-11-05 16:25:58 +08:00   ❤️ 1
    排查下 很快就能解决了
    WildCat
        5
    WildCat  
    OP
       2015-11-05 16:29:14 +08:00 via iPhone
    @huson 现在的 path 还不够模块化吗?具体怎么写才叫模块化?
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   4680 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 10:10 · PVG 18:10 · LAX 03:10 · JFK 06:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.