[英](sqlite3.OperationalError) no such table
我看到在我的目錄中創建的 db 文件,但我無法插入其中。 我的問題很基本,有人可以發現明顯的嗎?
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine
import models
DB_PATH = 'sqlite:////home/ali/test.db'
engine = create_engine(DB_PATH, echo=True)
Session = sessionmaker(bind=engine)
session = Session()
### Insert data into ProductionRun table ###
prod_run = models.ProductionRun(instance_id=df.instance_id.iloc[0], name=df.profile_name.iloc[0], host=df.host_box.iloc[0], default_config={})
session.add(prod_run)
session.commit()
這是我看到的錯誤
OperationalError: (sqlite3.OperationalError) no such table: ProductionRun
[SQL: INSERT INTO "ProductionRun" (instance_id, name, host, default_config) VALUES (?, ?, ?, ?)]
[parameters: (1, 'Apple', 'host1', '{}')]
(Background on this error at: http://sqlalche.me/e/13/e3q8)
這是models.py
中的ProductionRun
class ProductionRun(Base):
__tablename__ = 'ProductionRun'
id = Column(Integer, primary_key=True, autoincrement=True)
instance_id = Column(Integer, nullable=True)
name = Column(String, nullable=False)
host = Column(String, nullable=False)
default_config = Column(JSON, nullable=False)
status_change = relationship('ProductionRunStatusChange', back_populates='production_run')
因為是 Sqlite 表類需要在創建數據庫之前發生。
DB_PATH = 'sqlite:////home/ali/test.db'
engine = create_engine(DB_PATH, echo=True)
BASE.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.