The model `user` does not have a primary key attribute specified. It is required for all models to have a primary key attribute defined

I have defined a waterline model below:

var Waterline = require('Waterline');
var bcrypt = require('bcrypt');

var User = Waterline.Collection.extend({
identity: 'user',
datastore: 'myMongo',
autoPK: false,
attributes: {
    id: {
        type: 'integer',
        autoIncrement: true,
        primaryKey: true
    },
    email: {
        type: 'string',
        email: true,
        required: true,
        unique: true
    },
    username: {
        type: 'string',
        required: true,
    },

    image: {
        type: 'string'
    },

    password: {
        type: 'string',
        required: true
    },

    mobNo: {
        type: 'string',
        required: true
    },
    aadharNo: {
        type: 'string',
        required: true
    },

    toJSON: function () {
        var obj = this.toObject();
        delete obj.password;
        return obj;
    }
},

beforeCreate: function (values, next) {
    var bcrypt = require('bcrypt');

    bcrypt.genSalt(10, function (err, salt) {
        if (err) return next(err);

        bcrypt.hash(values.password, salt, function (err, hash) {
            if (err) return next(err);

            values.password = hash;
            next();
        });
    });
}
});

module.exports = User;

When initializing the application, I encountered an error regarding waterline:

userError: Could not find a primary key attribute on the model `user`. All models must contain an attribute that acts as the primary key and is guaranteed to be unique.
at normalizeCollection (C:\Users\shriko\WebstormProjects\baclasses\node_modules\waterline-schema\lib\waterline-schema\schema.js:85:44)
at arrayEach (C:\Users\shriko\WebstormProjects\baclasses\node_modules\@sailshq\lodash\lib\index.js:1439:13)
at Function.<anonymous> (C:\Users\shriko\WebstormProjects\baclasses\node_modules\@sailshq\lodash\lib\index.js:3500:13)
at schemaBuilder (C:\Users\shriko\WebstormProjects\baclasses\node_modules\waterline-schema\lib\waterline-schema\schema.js:34:5)
at new WaterlineSchema (C:\Users\shriko\WebstormProjects\balajiclasses\node_modules\waterline-schema\lib\waterline-schema.js:36:12)
at Object.initialize (C:\Users\shriko\WebstormProjects\baclasses\node_modules\waterline\lib\waterline.js:581:26)
at Object.<anonymous> (C:\Users\shriko\WebstormProjects\baclasses\bin\www:32:18)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3 

Despite setting autoPK to false and defining a manual primary key, I am still facing this issue.

I am using "waterline": "^0.13.1-9" with express. Any suggestions on how to create a primary key would be appreciated. Thank you!

Answer №1

Upon reviewing the validation code in the waterline-schema package, it is evident that the primary key must be specified in the schema definition.

var User = Waterline.Collection.extend({
identity: 'user',
datastore: 'myMongo',
autoPK: false,
primaryKey: 'id',
attributes: {
    id: {
        type: 'integer',
        autoIncrement: true,
        primaryKey: true
    }

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

Child component in Vue 2 not receiving defined props

After numerous attempts, I am still struggling to successfully pass a prop down to a child component. <Project :grossMarginPerResource="grossMarginPerResource" :threshold="threshold" :orderBy="orderBy" @refetch="refetc ...

Navigating with React Router and Express

As a Meteor user, I am curious about the distinction between Express and React Router Dom. In my experience with Meteor, I would typically render a component that included the browser router and routes. However, I find myself puzzled by the use of Expres ...

Using Node.js and Express.js to redirect users after a successful data insertion

I am currently developing a CRUD application in Nodejs/Expressjs using EJS as the templating engine. Within my "views" folder, I have created a subfolder named "login" which contains several .ejs files. All of my .ejs files are located within the views fo ...

The error "TypeError: res.json is not a function" occurs when the 'fs' module is required

Having trouble passing the contents of files I'm reading via res.json. It seems like I may be overwriting my res function, but I'm not sure what the solution is. app.get('/uploads/', (res, req) => { dirname = './cl ...

Tips for inserting a logo in the center of a QR code using Node.js

I'm currently working on designing a logo and attempting to incorporate it into the center of a QR code. While I've been successful in generating the QR code, I'm facing challenges in getting the logo to appear in the middle. I've tried ...

I'm curious if there is a method to incorporate localStorage into the initialState of Redux Toolkit within Next.js 14

Attempting to establish the initial value of a Redux Toolkit slice for dark mode using localStorage is proving problematic in Next.js, as the window object is not defined on the server-side, resulting in errors. The typical workaround involves using if (t ...

Installation of a cloned Parse server

I downloaded the Parse server repository from parse-server-example and set up MongoDB, as well as installed Node.js packages using npm install. However, when I try to start the app with npm start, I encounter this error in the terminal!! How can I resolve ...

Display debugging information in the console using bunyan

child.log.info('info'); child.log.debug('debug'); When running the command: node app.js | bunyan -o short -l debug I am encountering an issue where only INFO messages are displayed and DEBUG messages are not showing up. I want to be ...

I am seeking assistance with generating a printed list from the database

Struggling for two full days to successfully print a simple list from the database. Take a look at the current state of the code: function CategoriesTable() { const [isLoading, setLoading] = useState(true); let item_list = []; let print_list; useEffect(( ...

Uploading a JSON file to myjson.com using a jQuery PUT request in Node.js

As a novice in javascript, I have successfully retrieved a JSON object from on my HTML page using AJAX with the following code: $.getJSON("https://api.myjson.com/bins/bjm28", function (data) { $.each(data, function (index, value) { console.log ...

JQuery: Issue with closing modal on certain popups

I have configured a popup that is associated with 6 different products. While it functions correctly for the first product, it does not seem to work properly for the rest. <script> //var modal = document.getElementById("m ...

Utilizing React Native to Query, Filter, and Save a Single Document Field Value from Firestore Database into a Variable/Constant

My current task involves setting up a Firebase Firestore Database in order to filter it based on a specific field value within a document. The collection I am working with is named "PRD" and consists of thousands of documents, each sharing the same set of ...

What is the best way to transfer the value of a radio button, retrieved from a database, to a textbox?

Greetings, I am trying to figure out how to pass the value of a radio button to a textbox using jQuery and PHP. The radio buttons are generated dynamically based on rows from my database, so I set the row ID as the ID for each radio button. However, the co ...

What is the ideal location for integrating modular logic?

As I delve into the world of Node and Express, a simple query arises. It's so fundamental that giving it a title is proving to be challenging. My goal is to create a modular logic unit using multiple JavaScript files neatly organized within one direct ...

I'm looking for a way to implement an interactive auto slideshow in JavaScript that allows users to manually

Having spent a lot of time studying auto slideshows, I'm facing an issue where clicking on the bullet to show the next image results in the image disappearing suddenly. Initially, I thought the problem was with using addEventListener events, so I swi ...

Contrasting the use of jQuery versus AJAX for updating static page text

While I haven't fully grasped the concept of AJAX yet, my understanding is that it can be beneficial for updating specific parts of a webpage. Does using AJAX only make sense when you require server interaction? I am looking to replace text on a webp ...

What is the best way to update the content of a modal using jQuery and AJAX?

Despite previous inquiries on this matter, none of the answers provided have been helpful to me. Therefore, I am addressing the issue again... I am currently developing the frontend of a website that does not involve any backend functionality (no server c ...

Querying Firebase by the value of a child node

Here is how my structure looks like: 2017511 UcQefEaHJG6fteGsbsiaWjQ60d9Q62 value1: 50 value2: 1200 value3: "blabla" AcQefEaHJG6fteGsbsiaWjQ60d9Q62 value1: 55 value2: 2200 value3: "balabla" BcQefEaHJG6fteGsbsiaWjQ6 ...

Ignore one specific file when importing all files in Angular 7

In my Angular 7 project, I am utilizing C3 and importing all the necessary files at the beginning of my .ts component file using a wildcard. import * as c3 from 'c3'; While this method works well overall, I encountered an issue where my CSS ove ...

Crafting personalized objects from an array

In the process of creating an object from an array, I am faced with a dilemma. The elements in the array are as follows: var arr = [ 'find({ qty: { $lt: 20 } } )', 'limit(5)', 'skip(0)' ] Despite my efforts, my code is ...