admin管理员组

文章数量:1559090

【报错】sqlalchemy.exc.argumenterror: mapper mapped class myclass->myclass could not assemble any primary key columns for mapped table ‘myclass’

错误代码

class myclass(base):
    __tablename__ = "myclass"
    id = db.column(db.integer, nullable=false)
    latest_success_time = db.column(db.datetime, nullable=true)  
    latest_failed_time = db.column(db.datetime, nullable=true)   
    success_time = db.column(db.integer)  # 用例执行成功次数
    run_count = db.column(db.integer)  # 用例执行次数

错误原因

mysql创建的表必须包含一个主键,以上orm模型中,缺少主键,故创建失败

正确代码

class myclass(base):
    __tablename__ = "myclass"
    id = db.column(db.integer, primary_key=true, index=true)
    latest_success_time = db.column(db.datetime, nullable=true)  
    latest_failed_time = db.column(db.datetime, nullable=true)   
    success_time = db.column(db.integer)  # 用例执行成功次数
    run_count = db.column(db.integer)  # 用例执行次数

本文标签: