Mayank0255 / Stackoverflow-Clone-Frontend

Clone project of a famous Q/A website for developers built using MySQL, Express, React, Node, Sequelize :globe_with_meridians:
https://stackoverflow-clone-client.vercel.app
MIT License
546 stars 209 forks source link

Add new posts to database!!! from python terminal - it not show in all questions list #25

Closed a-nai closed 3 years ago

a-nai commented 3 years ago

I add this line to database {'id': 8, 'title': 'This is a simple herpes virus-jkjfghdkfjghdkghkgjhdkg', 'body': 'jkljlkjlj ghjgjg ghjhgjhg hghjghj', 'views': 0, 'created_at': datetime.datetime(2021, 1, 15, 3, 59, 13), 'user_id': 8, 'vote': 23, 'unique_id': 1, 'counter': 0, 'language': 'english'}] sucessfully

>>> def insertDBq(body,user_id,id,vote,unique_id,language,title):
...     mydb=mysql.connector.connect(host="localhost",user="root",password="password",database="stack_overflow_v2");
...     string="""REPLACE INTO posts(body, user_id, id, vote, unique_id, language,title) VALUES ('%s',%d,%d,%d,%d,'%s','%s');""" % (body,int(user_id),id,int(vote),unique_id,language,title);
...     mycursor.execute(string);
...     mydb.commit();
...     return print(mycursor.rowcount, "record inserted.");
... 
>>> insertDBq('jkljlkjlj ghjgjg ghjhgjhg hghjghj',8,8,23,1,'english','This is a simple herpes virus-jkjfghdkfjghdkghkgjhdkg')
1 record inserted.

but it won't to show at main page and when i got to mysite.com/questions/8 throw error to me 404

Mayank0255 commented 3 years ago

I think you have updated the schema and then you have updated the database with a new string of data. The issue can occue due to many reasons that you will need to clear up the database once as all the values inside should have the same schema. Another thing that you actually added data to the post only but how the postform works is that the tags are in MANY TO MANY relationship that's why it contains a different table and there's another table adjoining them named posttag I suppose which consists the relationship between them. So, you need to add info properly to the database with proper conventions and then try adding it. After adding refresh the homepage first as addpost adds post to the db but then the homepage is in dormant state and it does not gets updated automatically

a-nai commented 3 years ago

I also update posttag table - but not simultaneously - is it problem? Is it some connection that invisible in mysql tables?

I refresh page and nothing changed

Mayank0255 commented 3 years ago

Try restarting the server after adding, it should work or you are doing something wrong in the implementation

a-nai commented 3 years ago

http://178.154.224.104 - i get only 5 posts

http://178.154.224.104/questions/8 - empty

Mayank0255 commented 3 years ago

I am not sure what is it that you are doing as I have done these things alot of times while building the app. I won't be able to fix it as the issue is something else like the way you are executing thw problem, what you are trying to achieve, and lack of knowledge of mysql-express-react-node tech stack.