简体   繁体   中英

Database column in a while loop isn't getting changed

So I am changing a value inside my database on my website. I am sure it is getting changed. I am printing the value

computer.directory_response = "example" # not the actual value it's always changing
            db.session.commit()
            print(computer.directory_response)

I can see the printed value in the console. meanwhile, I have a program that sends a request to /computers/1/ajax-dir . the problem in the code is when I am doing a while loop to check if the value is example (to be sure I just implemented the if statement inside the while loop)

while(computer.directory_response == ""):
                if computer.directory_response != "":
                    break
                else:
                    pass

at the beginning it's empty. Yes. But even when I change the value in the first part of code I showed you it's still in the while loop. I don't understand why it doesn't change I am using flask as a backend language

It seems that you aren't adding the computer to the db.session .

As that's the case you should add this before the db.commit() :

db.session.add(computer) 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM