亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

一毛一樣的代碼為什么我報錯

#?_*_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))

http://img1.sycdn.imooc.com//6363550e0001b7ba15920615.jpg

正在回答

1 回答

你的?CompanyModel 沒有定義 id 字段

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

一毛一樣的代碼為什么我報錯

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號