The autoIncrement feature is causing a syntax error at or near "SERIAL"

Encountering a build error :

Unable to start server due to the following SequelizeDatabaseError: syntax error at or near "SERIAL"

This issue arises only when using the autoIncrement=true parameter for the primary key.

'use strict';

export default function(sequelize, DataTypes) {
  return sequelize.define('Ladder', {
    ladder_id: {
      type: DataTypes.UUID,
      allowNull: false,
      primaryKey: true,
      autoIncrement: true //<------- If commented it works fine
    },
    ladder_name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      unique: true
    },
    ladder_description: {
      type: DataTypes.TEXT,
      allowNull: true
    },
    ladder_open: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    ladder_hidden: {
      type: DataTypes.BOOLEAN,
      allowNull: false
    },
    ladder_creation_date: {
      type: DataTypes.DATE,
      allowNull: false
    },
    ladder_fk_user: {
      type: DataTypes.INTEGER,
      allowNull: false
    },
    ladder_fk_game: {
      type: DataTypes.UUID,
      allowNull: false
    },
    ladder_fk_platforms: {
      type: DataTypes.ARRAY(DataTypes.UUID),
      allowNull: false
    }

  },
    {
      schema: 'ladder',
      tableName: 'ladders'
    });
}

Running Sequelize version 3.30.4 and postgreSQL version 9.6.

The intention is to set autoIncrement to true in order to generate UUID with postgreSQL uuid_generate_v4().

Answer №1

While I'm not a regular user of sequelize, it's important to note that using autoIncrement for non-sequential columns in PostgreSQL may not be the best approach. Instead, consider adding an extension for generating UUID numbers easily, as PostgreSQL does not have a default UUID number generator. You can find more information about this at https://www.postgresql.org/docs/9.4/static/uuid-ossp.html. I assume you have already added this extension.

The next step would involve utilizing the sequelize.fn function.

This function creates an object representing a database function, which can be used in search queries within both 'where' and 'order' clauses, as well as in defining default values for column definitions.

Thus, your solution should look something like:

ladder_id: {
    type: DataTypes.UUID,
    allowNull: false,
    primaryKey: true,
    default: sequelize.fn('uuid_generate_v4')
}

Answer №2

It seems like the autoIncrement setting in PostgreSQL is hardcoded to use the SERIAL type for columns, which may be causing conflicts with your UUID choice.

To resolve this issue, consider removing the autoincrement parameter and using the defaultValue instead:

return sequelize.define('Ladder', {
    ladder_id: {
      type: DataTypes.UUID,
      allowNull: false,
      primaryKey: true,
      defaultValue: UUIDV4
    },

Answer №3

student_id: {
    primaryKey: true,
    incrementByOne: true,
    dataType: Sequel.STRING
},
teacher_id: {
    referencesTo: {
        dataModel: 'educator',
        primarykey: 'teacher_id'
    },
    dataType: Sequel.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

How to insert a span element within a link tag in Next.js/React.js

Looking to create a breadcrumb using microdata in a Next.js and React.js project. Initially, I tried the following: <li itemProp="itemListElement" itemScope itemType="https://schema.org/ListItem"> <Link href={'/index&a ...

Monitoring multiple items in OPC UA with Node.js

Utilizing the node-opcua module, my goal is to efficiently monitor multiple opc ua nodes through subscriptions. The desired workflow involves a user selecting nodes in an HTML UI, clicking a Monitor button which then sends the corresponding nodeIds as para ...

An issue with TypeORM syntax causing errors within a NestJS migration file

I recently encountered an issue while setting up PostgreSQL with NestJS and TypeORM on Heroku. Despite successfully running a migration, my application kept crashing. I attempted various troubleshooting methods by scouring through blogs, GitHub issues, and ...

how to implement dynamic water fill effects using SVG in an Angular application

Take a look at the code snippet here HTML TypeScript data = [ { name: 'server1', humidity: '50.9' }, { name: 'server2', humidity: '52.9', }, { name: 'server3', humidity: ...

Unexpected Memory Drain in Ionic and Cordova on iOS

I've encountered an unusual memory leak in my Ionic and Cordova application. This leak is not present when running the app in Chrome, but it clearly appears when I test the app. The issue arises when I need to iterate through a large data set and assi ...

Issue encountered while attempting to deactivate button until numerical data is entered in the OTP field using Vuejs

otp_value: '', isFadeout: false, verifyOtp() { this.disabled = true; this.otpBtnClicked = false; this.verified = true; }, <input class="o ...

Looking to retrieve the mouse coordinates using JavaScript

How can I use JavaScript to track the mouse position on a canvas? Upon visiting this page: http://billmill.org/static/canvastutorial/mouse.html They provide this code snippet: function initializeMouse() { canvasMinimumX = $("#canvas").offset().left; ...

Manipulating CSS Class Properties Using JavaScript

In my JavaScript application, there is a functionality that loads a list of items for users to click and view detailed information in a separate div on the page. Users should be able to interact with and make modifications to these individual item overview ...

Is it preferable to ensure that the ng-click function is completely resolved before moving on to

Lately, I've encountered an issue and the most straightforward solution that comes to mind is making sure that a function gets fully resolved before navigating to the href link. Is this something that can be achieved? Here's some additional info ...

Is there a way to update a child component in React when the parent state changes, without utilizing the componentWill

I am currently working on developing a JSON editor using React, but I am facing an issue with the library I am utilizing not having a componentWillReceiveProps hook. As someone relatively new to React, I am trying to find a way to automatically update th ...

dynamic jquery checkbox limit

I am working with the following HTML code: <input type="checkbox" id="perlengkapans" data-stok="[1]" onchange="ambil($(this))"> name item 1 <input type="checkbox" id="perlengkapans" data-stok="[4]" onchange="ambil($(this))"> name item 2 &l ...

The use of custom loaders alongside ts-node allows for more flexibility

Is it possible to utilize ts-node with a custom loader? The documentation only mentions enabling esm compatibility. ts-node --esm my-file.ts I am attempting to implement a custom loader for testing an ESM module, but I prefer not to rely on node for compi ...

Errors related to missing RxJS operators are occurring in the browser, but are not showing up in Visual Studio

Recently, I encountered a peculiar problem with my Angular4 project, which is managed under Angular-CLI and utilizes the RxJS library. Upon updating the RxJS library to version 5.5.2, the project started experiencing issues with Observable operators. The s ...

Is there a method to display a loading animation while the micro apps are being loaded in a single spa project?

Currently, I am working on a project using single spa and I need to implement a loader while my micro app is being loaded. Additionally, I also need the loader to be displayed when switching between these micro apps. Are there any methods to accomplish t ...

How can DataTables (JQuery) filter multiple columns using a text box with data stored in an array?

I've been attempting to create a multi-column filter similar to what's shown on this page () using an array containing all the data (referred to as 'my_array_data'). However, I'm facing issues with displaying those filter text boxe ...

What is the best way to store textarea information into a session using the jQuery AJAX post method in Codeigniter?

I am having trouble saving the text from a textarea to the Controller session using jQuery AJAX post method in Codeigniter Smarty. I am unable to save the data to the session. Can someone please provide me with guidance and a detailed example of how to ach ...

Mask the "null" data in JSON

I'm currently working with a JSON file and trying to display it in a bootstrap table. Check out the code snippet I've been using: $(document).ready(function(){ $.getJSON(url, function(data){ content = '<h1><p class="p1 ...

the router is having trouble choosing the right function

When attempting to log in a user using postman with the URL http://localhost:3000/login, it seems to always trigger the register function instead. The code itself is working fine, but it's just routing to the wrong function. How can I redirect it to t ...

Rearranging div placement based on the width of the screen

I am currently working on building a responsive website and I need two divs to switch positions depending on the screen width, both on initial load and when resizing. Despite my efforts in researching and trying various options, I have not been successful ...

Sequencing requests and processing data in Node.js through event handling

Is there a way to combine the responses from two requests into one single JSON response? The goal is to have an array containing both {response1JSON} and {response2JSON}, with each response streaming data that needs to be read. function getSongs() { c ...