I'm getting Error: ER_TABLE_EXISTS_ERROR: when trying to connect with mysql using node.js. I'm totally beginner in using sql database with node. all tables successfully created. but I'm still getting this error. I cannot find what makes this error. how can I resolve this. thanks!
const con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "discussions",
});
con.connect((err) => {
if (err) {
throw err;
}
let usql =
"CREATE TABLE users (id INT AUTO_INCREMENT PRIMARY KEY, name TEXT, profile TEXT)";
con.query(usql, (err, result) => {
if (err) {
throw err;
}
console.log("User Table created");
});
let csql =
"CREATE TABLE comments (id INT AUTO_INCREMENT PRIMARY KEY, comment TEXT, upvotes INT)";
con.query(csql, (err, result) => {
if (err) {
throw err;
}
console.log("Comments Table created");
});
let rsql =
"CREATE TABLE replies (id INT AUTO_INCREMENT PRIMARY KEY, reply TEXT, upvotes INT)";
con.query(rsql, (err, result) => {
if (err) {
throw err;
}
console.log("Replies Table created");
});
let sql =
"SELECT users.name AS user, comments.id AS comments FROM users JOIN comments ON users.comment_id = comments.id";
con.query(sql, (err, result) => {
if (err) {
throw err;
}
console.log(result);
});
let msql =
"SELECT comments.id AS comment, replies.id AS replyies FROM comments JOIN replies ON comment_id.reply_id = replies.id";
con.query(msql, (err, result) => {
if (err) {
throw er;
}
console.log(result);
});
});