Greetings all! I am curious about the strange error I encountered in the psql terminal

I am able to add new users using Postman with this model


    sequelize.define('users', {
            id: {
              type: S.INTEGER,
              allowNull: false,
              autoIncrement: true,
              primaryKey: true
            },
            name: {
              type: S.STRING,
              allowNull: false,
              validate: {
                notNull: {
                  msg: 'Name is required'
                },
                len: {
                  args: [2, 30],
                  msg: 'Name must be at least 2 characters long.'
                },
                isAlpha: true
              }
            },
            lastName: {
              type: S.STRING,
              allowNull: false,
              validate: {
                notNull: {
                  msg: 'Lastname is required.'
                },
                len: {
                  args: [2, 50],
                  msg: 'Lastname must be at least 2 characters long.'
                },
                isAlpha: true,
              },
            }
          })
        }

This is the express route I created Interestingly, the .findOrCreate function isn't functioning as expected! I had to split the system into .findOne and .create functions.


    server.post('/', async (req, res)=>{
      try {
        const { name, lastName } = req.body;
        if(!name || !lastName){
          res.send('All fields must be filled out')
        }
        const user = await Users.findOne({
          where: {
            email: email
          }
        })
        if(user){
          return res.send('This user already exists, please choose a different one!').status(100);
        }
        const createUser = await Users.create({
            name: name,
            lastName: lastName
        })
        return res.send(createUser)
      } 
      catch (err) {
        res.send({ data: err }).status(400);
      }
    })

The issue is that Postman works fine but when I try to insert data into the model through the psql terminal, it throws the following error:


        insert into users (name, lastName)
        values('John', 'Doe', '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea808e858faa8d878b8386c4898587">[email protected]</a>', '12345678', 'wherever');
    
    ERROR:  column "lastname" does not exist in table "users"
    LINE 1: insert into users (name, lastName)

Answer №1

If you are determined to add an extra challenge to your life by using upper case letters in your identifiers, be sure to enclose them in double quotes every time you reference them in SQL:

"username"

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

Error with the mongo (1.4.4) query

After running the query like this : collection.find({ "position": { $in: [ 1, 2 ] } }).toArray().... The correct result is returned. However, when I try using $and or $or, such as: collection.find({ $or: [ { "position": 1 }, { "position": 2 } ] }).toAr ...

Utilizing Angular PrimeNG's range datepicker, you can select a date range spanning from January 31st to December 1st, 2023 within a reactive form. Take it a step further by calculating

Here is some HTML code: <div class="row"> <div class="col-4"> <p-calendar label="startDate" formControlName="startDate" [minDate]="daMaxRange" ...

Why am I getting an overwhelming amount of results from my query?

I have a group of potential candidates, each with a history of one or more jobs at different companies where they used various skills. Below is a rudimentary representation: --------------- --------------- | ...

Error encountered with the Schema in expressjs and mongoose frameworks

I am currently working on integrating mongoDB with an expressjs project using mongoose, and I have encountered a specific error. throw new mongoose.Error.MissingSchemaError(name); ^ MissingSchemaError: Schema hasn't been registered for model ...

Troubleshooting a formatting problem with JSON retrieved from an AJAX POST request

Upon receiving a POST request via an ajax function, my PHP script returns JSON formatted data as follows: //json return $return["answers"] = json_encode($result); echo json_encode($return); The string returned looks like this: answers: "[{"aa":"Purple", ...

I attempted to utilize certain CSS properties, only to find that they were not being applied due to conflicts with Bootstrap's own CSS. I'm unsure what I should do next

click here for image .container, .container-fluid, .container-lg, .container-md, .container-sm, .container-xl, .container-xxl { --bs-gutter-x: 1.5rem; --bs-gutter-y: 0; width: 100%; **padding-right: calc(var(--bs-gutter-x) * .5);** **pa ...

Determining the state of a button based on a property's values

Is it possible to conditionally display a button based on the value of the sendSMS property of the logged-in user in AngularJS? How can I achieve this using ng-show in the HTML? I'm uncertain if I correctly assigned the value for the sendSMS property ...

Changing the size of the logo as you scroll through the page

I have implemented the following code to resize the logo as I scroll down the page. $(document).on('scroll', function() { if ($(document).scrollTop() >= 10) { $('.logo img').css('width', '50px'); } else ...

Iterate over an ASP.Net table using a loop

Currently, I am facing a challenge with looping through a table that is dynamically created using C#. I have a client-side checkbox that should trigger the loop each time it's clicked. While I believe I can manage the looping process itself, I am enco ...

How to send data to a compiled handlebars template in Express.js

I have been attempting to pass a variable to a handlebars compiled template, but instead of the correct value, I am getting a blank. Even though the console logs show the right object, I seem to be making a silly mistake somewhere. Despite trying multiple ...

Vue for Number Crunching

Learning vueJS is quite new to me. I am attempting to capture two input values, add them together, and display the result. I have encountered a strange issue where when subtracting number1 from number3, multiplying number1 with number2, or dividing number ...

Tips for reducing the size of a jade script tag efficiently with uglifyjs

I included the following script tag in my jade file: !!!5 html(lang="en") head body script(type='text/javascript') function something() { alert("test") } Is there a way to minimize this using uglifyjs or any ot ...

Communicating PHP variables with JavaScript through AJAX in a chat application

Hello there! I am currently in the process of developing a chat application for my website that includes user registration and login. My backend server is built using NodeJS to leverage SocketIO capabilities. Within my index.php file, I have implemented ...

Ensure that each customer is accounted for only once in this query

I am currently working with two tables: one contains a list of store locations along with their latitude and longitude coordinates, while the other table consists of a customer list with address details and corresponding lat/long data. My objective is to c ...

Tips for updating a field-List in MongoDB with Mongoose and Node.js

Hello there Stackoverflow team, I'm currently working on updating a user model in my nodeJs application using Express and Mongoose (MongoDB) to handle multiple "devices". Here's what my User model looks like: const userSchema = new Schema({ ...

Employ a for loop to generate custom shapes within the canvas

EDIT: I will be sharing all of my code including the HTML and JS. Pardon me for the abundance of comments. I am attempting to generate rectangles in a canvas using a for loop (taking user input) and then access them in another function to perform certain ...

BrowserSync Failing to Load

Recently started using BrowserSync and I'm trying to figure out how to make it work smoothly. My main file that contains all the code is named 'gulpwork'. Inside 'gulpwork', there are 4 folders - two for converting Pug from &apos ...

How to Translate SQL Query To LINQ?

I used to be familiar with LINQ, but it's been a while since I've worked with it. Unfortunately, I can't seem to remember how to convert this SQL query to LINQ. SELECT [CompanyName] ,[ContactPerson] ,[Address] ,[Email] ,[InA ...

Consolidate various outcomes into a single entity

Let's say I have three different queries: SELECT col1, col2 FROM tab1; SELECT colA, colB FROM tab2; SELECT colTest, colBlah FROM tab3; Each query will only return one result. Is there a way to combine these three results into a single table? The d ...

transferring information from the Quill text editor to the Node.js server

Is there a way to send data from Quilljs on the frontend to node.js on the backend? I've been searching for examples, but haven't found anything related to the backend. I tried reading the documentation for Quilljs, but I'm still struggling ...