当我在父进程中查询时,sqlalchemy.exc.NoSuchColumnError

时间:2017-06-16 21:28:45

标签: python python-3.x sqlalchemy

我正在处理来自严重性来源的大量数据,因此我使用了多重处理。我的过程适用于Python 3.5.2,SQLAlchemy(1.1.9)和PyMySQL(0.7.11)。

当我从命令行运行时,该过程开始:

$ python3 input_process.py

但我得到了例外:

sqlalchemy.exc.NoSuchColumnError: "Could not locate column in row for column 'fp_feed_types.id'"

以下是我的代码:

input_process.py

from feed_process.main_process import run

if __name__ == "__main__":
    run()

feed_process / main_process.py

from multiprocessing import Pool
from feed_process.models import FeedIn
from feed_process.models.db import DBSession    

def process_feed(feed_id):
    session = DBSession()    
    feed_in = session.query(FeedIn).get(feed_id)
    print(feed_in.feed_type)

def run(urls = None, feed_ids = None, num_workers = None):
    DBSession().query(FeedId).get(26)

    feed_ids = [1, 2, 3]

    with Pool(processes = num_workers) as pool:
        responses = [pool.apply_async(process_feed, (feed_id,)) for feed_id in feed_ids]

        for response in responses:
            response.get()

feed_process /模型/ db.py

from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

connection_string = ""

engine = create_engine(connection_string)
Session = sessionmaker(bind=engine)
DBSession = scoped_session(Session)

feed_process /模型/ model.py

Base = declarative_base()

class FeedType(Base):
    __tablename__ = "fp_feed_types"

    id = Column(String, primary_key = True)

class FeedIn(Base):
    __tablename__ = "fp_feeds_in"

    id = Column("feedid", Integer, primary_key = True)
    name  = Column("feedname", String)

    feed_type_id = Column(String, ForeignKey("fp_feed_types.id"))
    feed_type = relationship("FeedType")

如果我删除DBSession().query(FeedId).get(26)函数中的行run该过程效果很好:|。请注意,26是随机数。

是的,列'fp_feed_types.id'存在。

我做错了什么?

0 个答案:

没有答案