[Solved] TutorialsPoint – Flask – SQLAlchemy not working


The tutorial has an indentation problem in the student class.
The constructor code should be indented one level so it becomes a method of the student class.

Corrected code: (note the indent of “def init(self, name, city, addr,pin):” in the code below)

class students(db.Model):
   id = db.Column('student_id', db.Integer, primary_key = True)
   name = db.Column(db.String(100))
   city = db.Column(db.String(50))
   addr = db.Column(db.String(200)) 
   pin = db.Column(db.String(10))

   def __init__(self, name, city, addr,pin):
      self.name = name
      self.city = city
      self.addr = addr
      self.pin = pin

The reason is, if that indent is not there, python will not see this function as a constructor of the student class. So the constructor with the matching number of arguments is not found, resulting in the error.

7

solved TutorialsPoint – Flask – SQLAlchemy not working