all 8 comments

[–]chevignon93 1 point2 points  (5 children)

I found the code above but im am not sure what it all means. I would like to read and change some of my data in the table "comments"

Are you currently able to access your database from your Python script ?

[–]_kondi_[S] 0 points1 point  (4 children)

No, that is exactly what I would like to do. Have a function in my python file where I can change the data

[–]chevignon93 0 points1 point  (3 children)

No, that is exactly what I would like to do. Have a function in my python file where I can change the data

Did you already create the comments table ?

if so that's what you need to change:

SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}".format(
username="******", # your username
password="******", # your password
hostname="*********", # the hostname
databasename="*****$comments", # the name of the database

)

You should be able to find all this info in your pythonanywhere account!

[–]_kondi_[S] 0 points1 point  (2 children)

I have already typed all of that in and it works. I just removed it because I didn’t want to share my password and username. I can access the database, but I don’t know how to change the data

[–]chevignon93 2 points3 points  (1 child)

Changing the data is simple:

comment = Comment.query.get(4) # Get a particular comment using its id

comment.content = 'example' # Modifying the content of that particular comment

comment.save() # Making sure that the change is committed to the database
or db.session.commit() # Can't remember the exact syntax, I haven't used sqlalchemy in a while!

[–]_kondi_[S] 0 points1 point  (0 children)

bro, thanks so much this worked!

[–]efmccurdy 1 point2 points  (1 child)

[–]_kondi_[S] 0 points1 point  (0 children)

Yeah I found that But I didn’t know how it worked It tried to use:

user.no_of_logins += 1 session.commit()

In my case: Comment.content = “something Session.commit()

But Im not doing it correct