Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9129233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:41:56+00:00 2026-06-17T07:41:56+00:00

I have created a table in postgresql 9 create table stillbirth(id serial primary key,

  • 0

I have created a table in postgresql 9

create table stillbirth(id serial primary key, state varchar(100), count int not null, year int not null); 

trying to write a sample on node.js with sequelize 1.4.1 version.

mapped the above table as

var StillBirth = sequelize.define('stillbirth',
{ id: {type: Sequelize.INTEGER, primaryKey: true, autoIncrement: true},
state: Sequelize.STRING,
year: Sequelize.INTEGER,
count: Sequelize.INTEGER
}, {timestamps: false, freezeTableName: true});

now when i try to create a new instance of Stillbirth and save it, i get errors.

/** new instance create code **/

StillBirth
   .build({state: objs[j].state, year: objs[j].year, count: objs[j].count})
   .save()
   .error(function(row){
         console.log('could not save the row ' + JSON.stringify(row));
        })
   .success(function(row){
       console.log('successfully saved ' + JSON.stringify(row));
   })

error i get

*Executing: INSERT INTO “stillbirth” (“state”,”year”,”count”,”id”) VALUES (‘Andhra Pradesh’,2004,11,NULL) RETURNING ;
could not save the row {“length”:110,”name”:”error”,”severity”:”ERROR”,”code”:”23502″,”file”:”execMain.c”,”line”:”1359″,”routine”:”ExecConstraints”}

If you look at the sql that its generating, it puts null for the primary key which should ideally be generated by the db.

Can someone help me as to what am i missing here ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:41:57+00:00Added an answer on June 17, 2026 at 7:41 am

    You have to instantiate Sequelize with a special flag called omitNull:

    var sequelize = new Sequelize('db', 'user', 'pw', {
      omitNull: true
    })
    

    This will disable inserting undefined values as NULL. http://sequelizejs.com/#usage-options

    You might need to update to v1.5.x or 1.6.0-betaX

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY,
In PostgreSQL I have a table CREATE TABLE cubenotification.newnotification ( idnewnotification serial NOT NULL,
I have created table and inserted values as below. create table mytable (id INT,
I have created one table using the below command: create table Table1( Id int
I have 2 tables: CREATE TABLE article ( id serial NOT NULL, title text,
I'm new to PostgreSQL. I have tables like: CREATE TABLE Person ( ID SERIAL
I have the following table of counters: CREATE TABLE cache ( key text PRIMARY
I have this table in postgreSQL v9.1: CREATE TABLE ad_treenodemm ( ad_tree_id numeric(10,0) NOT
I have created a table CREATE TABLE mytable (food VARCHAR(20) references myfood(BIN) ,name NUMERIC(2)
I have created a table in postgreSQL. I want to look at the SQL

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.