Я получаю следующую ошибку, если добавляю «связь»:
(psycopg2.IntegrityError) значение NULL в столбце \ "robot_id \" нарушает
ограничение not-null \ nDETAIL: строка с ошибками содержит (25,
P-SVWD5SX_cJXiUyDM41oHhcwkxYcSoG33vMrtXbbvI, null)
Модель:
class Robot(Base, SQLTableJsonEncoder):
__tablename__ = 'robots'
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String, nullable=False)
hmac_secret = sa.Column(sa.String, nullable=False)
user_id = sa.Column(sa.String, sa.ForeignKey('users.public_id', ondelete='CASCADE'))
api_key = relationship('ApiKey', uselist=False)
class ApiKey(Base):
__tablename__ = 'api_keys'
id = sa.Column(sa.Integer, primary_key=True)
key = sa.Column(sa.String, nullable=False)
robot_id = sa.Column(sa.Integer, sa.ForeignKey('robots.id', ondelete='CASCADE'))
СЕРВИС
async def delete_robot(self, user, robot_id):
robot = super().get_first(mapped=Robot, user_id=user.public_id, id=robot_id)
if not robot:
raise NotFound(payload='Check your robot id')
super().delete(robot)
return robot.id