Encountering validation issues while using Sequelize.js

Trying to ensure that a username and password cannot be null during a post request to avoid empty rows, but encountering an error:

Express server listening on port 5000

/Users/ra/Desktop/Jos/node_modules/sequelize/lib/dao-validator.js:216
      throw new Error("Invalid validator function: " + validatorType)
            ^
Error: Invalid validator function: allowNull

Below is the model for the employer:

'use strict';

var Sequelize = require('sequelize');

module.exports = function (sequelize) {
    var Employer = sequelize.define("employer", {
        username: { type: Sequelize.STRING, validate: { allowNull: false } },
        password: { type: Sequelize.STRING, validate: { allowNull: false } }
    });
    return {
        Employer: Employer
    };
};

Answer №1

allowNull should be included in field options, not within the validator function: var Sequelize = require('sequelize');

'use strict';

var Sequelize = require('sequelize');

module.exports = function (sequelize) {
    var Employee = sequelize.define("employee", {
        name: { type: Sequelize.STRING, allowNull: false },
        age: { type: Sequelize.INTEGER, allowNull: false }
    });
    return {
        Employee: Employee
    };
};

For more information, please refer to the documentation here and source code comment here

Prior to Sequelize 2.0, the notNull validator could be used, but it was removed in version 2.0 (check here for 2.0 changes)

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

Adjust the text within a span using JavaScript when different options are chosen dynamically

My goal is to dynamically change the text of a span based on the selected option. I am utilizing Django + Python to generate these options. Below is the code snippet: <select class="form-control" id="materials"> {% for material2 in materials %} ...

Issue related to conflicting jQuery references and receiving multiple versions of jQuery simultaneously

Despite having only a reference to jQuery version 1.9.1 in the scripts, version 1.8.2 is somehow being added to the solution. The script used to add it is: bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js")); Althou ...

JavaScript updates the cursor after the completion of the JS function

Here is some code that I have been working with: <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> </head> <body style="background-color:yellow;width ...

How do I access Google Chrome and perform a Google image search within a Node.js/Electron program?

I am currently working on incorporating Google Image search into my Electron-based photo application. My goal is to have users click on a button labeled "Search Google for Image," which will then open up Chrome (if installed) with the local image file in ...

What are the steps for integrating Socket.IO into NUXT 3?

I am in search of a solution to integrate Socket.IO with my Nuxt 3 application. My requirement is for the Nuxt app and the Socket.IO server to operate on the same port, and for the Socket.IO server to automatically initiate as soon as the Nuxt app is ready ...

NGINX reverse proxy causing issues with Express server functionality

Currently, I am conducting a test on my express server that is running through a proxy. The nginx configuration file found in sites-available is as follows: server { server_name open.yousico.com; gzip on; gzip_proxied any; gzip_types application/j ...

What are the steps to import a .obj 3D model into Three.js?

After incorporating your advice, here is the revised code: var renderer = new THREE.WebGLRenderer( { alpha: true } ); renderer.setSize( window.innerWidth, window.innerHeight ); element.appendChild( renderer.domElement ); var loader = new THREE.OBJLoader( ...

Mastering the art of crafting form elements with jQuery

My code is looking like this: <!DOCTYPE html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script> function afterText() { var textElement = document.create ...

Maximizing Server Performance with Query Data Caching

I am currently developing an Express app that involves transferring data from views to a database. However, the majority of the data needs to be linked to other data within different tables in the database. For instance, there is a "choose student name" d ...

The error "this expression cannot be constructed" occurs when selecting dynamic properties in TypeScript

Initially, I have the following code snippet where I aim to dynamically choose a network in a straightforward manner. import * as Ethereum from '@multiplechain/ethereum/node' import * as Bitcoin from '@multiplechain/bitcoin/node' import ...

What is the best way to extract the data from an object received in an AJAX GET request?

I am fetching a variable object type from an Ajax get request and my goal is to access the values within a table row in that object. $.get(url2, function (responseGET) { var responseGETHtml2 = $(responseGET).find(".data-item-form form.form" ...

Creating a custom design for legends in Chart.js

I'm currently working on a project using chart.js and I'm trying to customize the label/legend styling for my chart. My goal is to replace the rectangular legend with a circular one. I've come across the suggestion of creating a custom legen ...

Tips for recognizing the click, such as determining which specific button was pressed

Currently, I am utilizing Angular 6. On the customer list page, there are three buttons - "NEW", "EDIT", and "VIEW" - all of which render to one component. As a result, it is crucial for me to determine which specific button has been clicked in order to ...

My goal is to calculate a precise percentage for each text field and then determine the overall grade

<tr> <td>Knowledge</td> <td><input type="text" name="Knowledge" style="height: 30px; width: 220px;" class="computethis" id="knowledge" Placeholder = "Enter Grade" autocomplete ="off" /></td> </tr> <tr&g ...

Is it necessary for React DOM to utilize className? I find it peculiar that I'm not receiving any alerts or warnings

I've been experimenting with React in a project for several weeks now. It just crossed my mind that I should be using className instead of class in regular DOM and SVG elements, as class is a reserved keyword in JavaScript. Despite this realization, ...

CSS selector targeting the value inside a textbox

I am working in an environment that only supports CSS and Bootstrap 3.2, with no JavaScript functionality. My current task involves creating a list filtering solution using pure CSS selectors and HTML. Imagine I have 2 items within an HTML list element. T ...

Tips for sending multiple JSON objects using the ajax() method

As of now, I have successfully implemented a $.getJSON() call to fetch a JSON string from a specific URL. Here is the simplified code that is currently functioning well: $.getJSON("myURL",function(data){ var receivedJSON = data; }); The retrieved JSO ...

Controlling setInterval internally in JavaScript: A guide

While developing my application, I have implemented the following code snippet: setInterval(function() { // some code // goes here }, 60000); The goal is to run certain code on a 1-minute interval, but sometimes it may take 2-3 minutes to complete. ...

triggering a function upon completion of the data append following the completion of the ajax requests

My task involves fetching data from three tables using an array of table names. The code snippet provided below demonstrates this process. Once the data is successfully appended to the DOM, I need to trigger the successMessage method. Currently, I am ach ...

Simulating NextJS router triggers using Jest

I've been attempting to simulate NextJS router events using Jest. I came across a useful resource at NextJS router & Jest. The approach outlined there closely resembles mine. Unfortunately, the solution provided in that post is not yielding the d ...