You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
create @oleeks it's not a bug. You'll need to use _password instead of password since the property of the class is _password, and password is the column name, so it should not be used to create the instance.
I get what you're trying to do, but this doesn't work as property on Model.create.
@wwwjfy thanks, but sqlalchemy can be used like this, so I thought it was compatible
DB_URI = 'mysql+pymysql://{username}:{password}@{hort}:{post}/{db}?charset-utf8'.format(
username=USERNAME, password=PASSWORD, hort=HOST, post=POST, db=DATABASE)
engine = create_engine(DB_URI)
Base = declarative_base(engine)
class User(Base):
__tablename__ = 'user'
id = Column(Integer, primary_key=True, autoincrement=True)
name = Column(String(20))
age = Column(Integer)
_password = Column(String(128), name='password', nullable=False)
@property
def password(self):
raise AttributeError('password is not readable')
@password.setter
def password(self, password):
self._password = password
# Base.metadata.create_all()
session = sessionmaker(engine)()
def init_data():
user = User(name='fantix', age=18, password='123456')
session.add(user)
session.commit()
if __name__ == "__main__":
init_data()
@wwwjfy thanks, but sqlalchemy can be used like this, so I thought it was compatible
Originally posted by @oleeks in #685 (comment)
The text was updated successfully, but these errors were encountered: