How does flask get self-increasing id after db.session.add

-sharp models
class User(db.Model):
    __tablename__ = "users"
    id = db.Column(db.BigInteger, primary_key=True)
    name = db.Column(db.VARCHAR(50), nullable=False)
    email = db.Column(db.VARCHAR(200), nullable=False)
    -sharp  NULL
    mobile = db.Column(db.VARCHAR(20), server_default=text("NULL"))

    -sharp 
    password = db.Column(db.VARCHAR, nullable=False)

    -sharp 
    _2fa = db.Column(db.VARCHAR(32), nullable=True)

    -sharp 
    created_at = db.Column(db.TIMESTAMP(False), nullable=False, server_default=text("now()"))

    __table_args__ = (
        Index("idx_users_name", func.lower("name"), unique=True),
        Index("idx_users_email", func.lower("email"), unique=True)
    )

    def __init__(self):
        if not self.created_at:
            self.created_at = now().format()

    def __repr__(self):
        return "<User %s>" % self.name

but there is no duplicate name and email

in the database.
Apr.27,2021

found on the Internet, you can take a look at https://www.crifan.com/sqlalc.

.

before the commit is submitted, db.session.flush ()
print the id of the object to get the new ID
choice = Choice (name=name, right=right)

    db.session.add(choice)
    db.session.flush()
    print("choice: ", choice.id)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2beb3-2ae37.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2beb3-2ae37.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?