I'm using Fastapi, Fastapi Users and TortoiseOrm for auth on my project.
I followed the example on FastApi Users website and when I try to add some extra fields at register users, get this error:
RuntimeError: no validator found for <class 'tortoise.fields.data.CharField'>, see arbitrary_types_allowed in Config
Here is my code, thanks for your help!
from tortoise import fields
from tortoise.contrib.pydantic import pydantic_model_creator
from fastapi_users import models
from fastapi_users.db import TortoiseBaseUserModel, TortoiseUserDatabase
from tortoise.contrib.starlette import register_tortoise
class User(models.BaseUser):
nombre = fields.CharField(max_length=100)
apellidos = fields.CharField(max_length=100)
class UserCreate(models.BaseUserCreate):
pass
class UserUpdate(User, models.BaseUserUpdate):
pass
class UserDB(User, models.BaseUserDB):
pass
class UserModel(TortoiseBaseUserModel):
pass
user_db = TortoiseUserDatabase(UserDB, UserModel)
I faced a similar error while using FastAPI Users with SQlAlchemy. What worked for me was to add the custom fields (nombre and appelidos in your case) to each of the 4 user models AND to the UserModel table while defining it
schemas.py file
models.py file