Reputation: 31
Flask Sqlalchemy Model
class Supplier(db.Model):
__tablename__ = 'SUPPLIER'
supplier_id = db.Column(db.Integer, primary_key=True)
supplier_name = db.Column(db.Text, nullable=False)
enable = db.Column(db.Boolean, nullable=False, default=True)
insert_date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
When I m trying to add a new supplier, I got the error
db.session.add(Supplier(supplier_name="sup"))
db.session.commit()
Stack Trace:
db.session.add(supplier_name="sup")
File "<string>", line 2, in __init__
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 376, in _new_state_if_none
state = self._state_constructor(instance, self)
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\util\langhelpers.py", line 883, in __get__
obj.__dict__[self.__name__] = result = self.fget(obj)
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\instrumentation.py", line 202, in _state_constructor
self.dispatch.first_init(self, self.class_)
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\event\attr.py", line 322, in __call__
fn(*args, **kw)
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\mapper.py", line 3367, in _event_on_first_init
configure_mappers()
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\mapper.py", line 3255, in configure_mappers
mapper._post_configure_properties()
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\mapper.py", line 1950, in _post_configure_properties
prop.init()
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\interfaces.py", line 196, in init
self.do_init()
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\relationships.py", line 1983, in do_init
self._process_dependent_arguments()
File "c:\program files (x86)\microsoft visual studio\shared\python37_64\lib\site-packages\sqlalchemy\orm\relationships.py", line 2012, in _process_dependent_arguments
setattr(self, attr, attr_value())
TypeError: id() takes exactly one argument (0 given)
I already tried the below methods, but still not working.
add Sequence
id_seq = db.Sequence('id_seq')
supplier_id = db.Column(db.Integer, id_seq, server_default=id_seq.next_value(), primary_key=True)
add constructor
def __init__(self, supplier_name):
self.supplier_name = supplier_name
I already make sure the table exists, and all columns been generated successfully. Seems not only this table has this issue, but any table I insert will also raise this error. Previously I use PostgresDB no issue, now I switch to oracle have this error. Please help!
Upvotes: 2
Views: 279
Reputation: 31
I figured out myself.
Last 3 lines, remote_side should be "node_id" not "id"
Upvotes: 1