The Query.formatError message indicates that there is an issue with the 'users.email' column in the where clause of the database query

I'm having some trouble with a piece of code. Here's my signup function :

exports.signup = (req, res) => {
// Adding User to Database
console.log("Processing func -> SignUp");

User.create({
    name: req.body.name,
    username: req.body.username,
    lname: req.body.lastname,
    email: req.body.email,
    password: bcrypt.hashSync(req.body.password, 8)
}).then(user => {
    Role.findAll({
        where: {
            name: {
                [Op.or]: req.body.roles
            }
        }
    }).then(roles => {
        user.setRoles(roles).then(() => {
            res.send("User registered successfully!");
        });
    }).catch(err => {
        res.status(500).send("Error -> " + err);
    });
}).catch(err => {
    res.status(500).send("Fail! Error -> " + err);
})

}

Now, let's check for duplicate users

checkDuplicateUserNameOrEmail = (req, res, next) => {
// Checking if Username is already in use
User.findOne({
    where: {
        username: req.body.username
    }
}).then(user => {
    if (user) {
        res.status(400).send("Fail -> Username is already taken!");
        return;
    }

    // Checking if Email is already in use
    User.findOne({
        where: {
            email: req.body.email
        }
    }).then(user => {
        if (user) {
            res.status(400).send("Fail -> Email is already in use!");
            return;
        }

        next();
    });
});

}

User export details

module.exports = (sequelize, Sequelize) => {
const User = sequelize.define('users', {
    name: {
        type: Sequelize.STRING
    },
    username: {
        type: Sequelize.STRING
    },
    password: {
        type: Sequelize.STRING
    }
});

return User;

}

Finally, addressing the issue encountered

An error occurred: Unknown column 'users.email' in 'where clause' at Query.formatError (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\sequelize\lib\dialects\mysql\query.js:244:16) at Query.handler [as onResult] (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\sequelize\lib\dialects\mysql\query.js:51:23) at Query.execute (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\mysql2\lib\commands\command.js:30:14)
at Connection.handlePacket (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\mysql2\lib\connection.js:449:32) at PacketParser.Connection.packetParser.p [as onPacket] (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\mysql2\lib\connection.js:72:12) at PacketParser.executeStart (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\mysql2\lib\packet_parser.js:75:16) at Socket.Connection.stream.on.data (C:\Users\Itzik\Desktop\לימודים\projact3\server\node_modules\mysql2\lib\connection.js:79:25) at Socket.emit (events.js:198:13) at addChunk (_stream_readable.js:288:12) at readableAddChunk (_stream_readable.js:269:11) at Socket.Readable.push (_stream_readable.js:224:10) at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)

Answer №1

After reviewing your create query, it is recommended to make the following updates to your model before trying again:

const User = sequelize.define('users', {
    name: {
        type: Sequelize.STRING
    },
    lname: {                        // <---- PLEASE ADD THIS FIELD
        type: Sequelize.STRING
    },
    username: {
        type: Sequelize.STRING
    },
    email: {                        // <---- PLEASE ADD THIS FIELD
        type: Sequelize.STRING
    }
    password: {
        type: Sequelize.STRING
    }
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

"Implementing middleware controls for email duplicates can prevent poorly designed code structures

I'm looking to implement a node.js express middleware for controlling duplicate emails, and I need a simple and concise code snippet for this. Here is the code from my middleware.js file: // ----------------------------------- MIDDLEWARE FUNCTION ...

The React callback is failing to update before navigating to the next page

I'm facing an issue that seems like it can be resolved through the use of async/await, but I am unsure of where to implement it. In my application, there are three components involved. One component acts as a timer and receives a callback from its pa ...

Extracting JSON data from JSON file

I've been working on a script to delete an entry from a JSON file. The JSON file structure includes an array of users like this: { "users": [ { "username": "test1", "answers": [ "Red", "Blue", "Yellow", ...

Transform React.js data from MySql into a variable

Hello there! I encountered an issue while working on coding my web app. **I am looking to execute this class only if the "swishes" value retrieved from a table in my MySQL database is greater than 0.** var thepos = 1; export default class W ...

Utilize Axios in Vue.js to fetch and process data from a REST API endpoint in C#

After successfully creating and deploying an API on Azure, I am trying to display the response in an alert box using javascript (Vue.js). The test method of my API returns the string "working". You can test the API here. This is the code snippet from my A ...

Guide on applying CSS to option tag within a select element in VUE.js

I am attempting to design a dropdown menu that resembles the one shown in the image. However, I'm currently unable to include any CSS styling. Can anyone provide guidance on how to create a customizable select dropdown in Vue? https://i.stack.imgur.c ...

Code in JavaScript using VueJS to determine if an array includes an object with a certain value in one of its elements

I have a scenario where I need to address the following issue: I have an Object with a property called specs. This property consists of an Array that contains several other Objects, each having two properties: name value Here is an example of what my o ...

The KOA / node.js outer function triggers a response while the callback is still in progress

Apologies for the title, I couldn't come up with something better. I thought I had a good grasp on Node.js / KOA, especially the basics, but now I'm starting to realize that I may be missing some essential knowledge. Let's examine the code ...

Problems with navigation, not functioning properly due to issues with Pulled functions

I am still getting the hang of things and struggling with the terminology, so please bear with me as I try to explain my issue. Currently, I am working on a project in react native where I have two files - Header.js and footer.js. I have successfully impo ...

Convert image buffer to string using Mongoose getter?

I have developed a basic node backend application modeled after eBay. I am now working on creating a react frontend app to complement it. Within the app, users can list items for sale and include a photo with their listing. The item information is stored ...

The onClick event for a q-btn does not seem to be functioning properly when used

Inside the q-btn, there is a q-checkbox. Additionally, I included a div to style the text. <q-btn flat color="blue" class="full-width no-padding" @click="tog(item)" > <q-checkbox ...

The declaration file for module 'react-scroll-to-bottom' appears to be missing

I recently added react-scroll-to-bottom to my project and it is listed in my dependencies. However, I am encountering the following error: Could not find a declaration file for module 'react-scroll-to-bottom'. The path 'c:/Users/J/Desktop/w ...

Issue with alignment in the multiselect filter of a React data grid

In React Data Grid, there is a issue where selecting multiple filter options messes up the column headers. Is there a solution to display selected filter options above a line in a dropdown rather than adding them to the column header? The column header siz ...

com.parse.ParseRequest$ParseRequestException: incorrect JSON response encountered during transition to Heroku for Parse server

I recently transitioned my Parse server from Heroku and my database from parse.com to MangoLab. However, I am encountering an error when making requests from my Android app. com.parse.ParseRequest$ParseRequestException: bad json response Here is the code ...

What is the method for determining the data type of a column in an Excel sheet that has been

Currently, I am utilizing the XLSX npm library to convert an Excel sheet into JSON format. However, all of the retrieved data is currently being returned as strings. To see a demo of the XLSX read process, you can visit this Stackblitz demo Is there a w ...

Ways to insert user data into a hidden input field

I am facing an issue with the input field on my website. Users can enter their desired input, and this data is copied into a hidden input field. However, the problem arises when new data replaces the old data. This is where I copy all the data: $('# ...

Encountering difficulties with the functionality of Google Places API

I am attempting to incorporate the autocomplete functionality of Google Places API into a text field. Below is the code I have implemented: <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"> </script> <script ...

Modifying the structure of serialized data

After serializing a JS form, the data looks like this: .....&xx=xxx&otherError=&input=SMS&message=sdfgs&...... Can anyone provide guidance on how to replace the value of message with the content of a textarea before making an ajax cal ...

The "mkdir" command is malfunctioning in an npm script on Linux, whereas it is functioning properly

My "prebuild" script is designed to create a specific folder structure: mkdir -p dist/{server,shared,client/{css,js,fonts,img}} The desired output should be: dist server shared client css js fonts img When I ...

Comparing $.fn.fancybox and $.fancybox: What sets them apart?

I'd like to understand the distinction between the two items shown above. In what ways do they differ from each other? ...