yu444913387
2022-11-03 13:43
# _*_coding:utf-8_*_ from datetime import datetime, date from typing import List, Optional from sqlalchemy import Column, Integer, String,ARRAY from sqlalchemy.ext.declarative import declarative_base from pydantic import BaseModel, constr Base = declarative_base() class CompanyOrm(Base): __tablename__ = 'companies' id = Column(Integer, primary_key=True, nullable=False), public_key = Column(String(20), index=True, nullable=False,unique=True) name = Column(String(50), unique=True) domains = Column(ARRAY(String(100))) class CompanyModel(BaseModel): public_key: constr(max_length=20) name: constr(max_length=50) domains: List[constr(max_length=100)] class Config: orm_mode = True co_orm = CompanyOrm( id=123, public_key='foobar', name='Testing', domains=['example.com', 'foobar.com'], ) print(CompanyModel.from_orm(co_orm))
你的 CompanyModel 没有定义 id 字段
高性能 FastAPI 框架入门精讲
12295 学习 · 87 问题
相似问题