Attributeerror: 'Nonetype' Object has no attribute 'append'

Asked

Viewed 115 times

1

A relationship Many to Many between the table Patient and Illnesses, and Patient and Allergies I am with the following problem.

pacientes_alergias = db.Table('pacientes_alergias',
    db.Column('paciente_id', Integer, ForeignKey('paciente.id'), primary_key=True),
    db.Column('alergias.id', Integer, ForeignKey('alergias.id'), primary_key=True)
    )


pacientes_doencas = db.Table('pacientes_doencas',
    db.Column('paciente_id', Integer, ForeignKey('paciente.id'), primary_key=True),
    db.Column('doencas.id', Integer, ForeignKey('doencas.id'), primary_key=True)
    )


class Paciente(Pessoa):
__tablename__ = 'paciente'
id = db.Column(Integer, primary_key=True)
doenca = relationship('Doencas', secondary=pacientes_doencas, lazy='subquery', backref=db.backref('pacientes', lazy=True), uselist=True)
alergia = relationship('Alergias', secondary=pacientes_alergias, lazy='subquery', backref=db.backref('pacientes', lazy=True), uselist=True)

class Alergias(db.Model):
__tablename__ = 'alergias'
id = db.Column(Integer, primary_key=True)
alergia = db.Column(String(30), unique=True)

class Doencas(db.Model):
    __tablename__ = 'doencas'
    id = db.Column(Integer, primary_key=True)
    doenca = db.Column(String(30), unique=True)

The problem is that when I perform allergy inclusion in the patient, it occurs without problem, but inclusion of diseases of error.

p = Paciente()
p.alergia.append(Alergias.query.first())

p.doenca.append(Doencas.query.first())
AttributeError: 'NoneType' object has no attribute 'append'

Already with allergies, he performs the append without problem. Regardless of what I do, the disease in the patient does not perform append, even implementing it as a list.

type(p.alergia)
sqlalchemy.orm.collections.InstrumentedList
type(p.doenca)
NoneType
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.