Reputation: 844
this might be a noob question but i keep getting this error for no reason
__init __() missing 1 required positional argument: 'id'
class test1(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True) # <-- it's right there
idNo = db.Column(db.Integer,unique=True)
Name = db.Column(db.String(255))
Type = db.Column(db.String(255))
Date = db.Column(db.String(255))
style = db.Column(db.String(255))
from = db.Column(db.String(255))
pCode = db.Column(db.String(25),unique=True)
def __init__(self,id,idNo,Name,Type,Date,style,from,pCode):
self.id = id # <-- it's right there
self.idNo= idNo
self.Name = Name
self.Type = Type
self.Date = Date
self.style = style
self.from = history
self.pCode = pCode
jD = {idNo:"Integer_value",Name:"value",Type:"value",Date:"value",style:"value",from:"value",pCode:"value"}
for j in jD:
x = test1(
idNo=j["idNo"],
Name=j["Name"],
Type=j["Type"],
Date=j["Date"],
style=j["style"],
from =j["from"],
pCode=pCode)
db.session.add(x)
i keep getting this error on Python >> __init__() missing 1 required positional argument: 'id'
am I suppose to mention the "integer Auto Increment " while making a new class ?
or do i have to remove it from class test1()
and __init __()
?
Upvotes: 1
Views: 3546
Reputation: 156
Either pass value of id while creating test1 object or remove "id" param from init function, because init is expecting id while creating object. Auto increment of "id" can be handle by database. So you don't need to set the value of "id" using code.
Upvotes: 4