null value violates not-null constraint on id, postgres
See original GitHub issuehi there.
attempting to create() a new instance of my menu object, as described here:
module.exports = function(sequelize, DataTypes) {
return sequelize.define('menu', {
title: {
type: DataTypes.STRING,
allowNull: false,
},
closed_view_title: {
type: DataTypes.STRING,
allowNull: false,
},
closed_view_photo_url: {
type: DataTypes.STRING,
allowNull: false,
},
closed_view_message: {
type: DataTypes.STRING,
allowNull: false,
},
soldout_view_title: {
type: DataTypes.STRING,
allowNull: false,
},
soldout_view_photo_url: {
type: DataTypes.STRING,
allowNull: false,
},
soldout_view_message: {
type: DataTypes.STRING,
allowNull: false,
},
max_items_per_order: {
type: DataTypes.INTEGER,
allowNull: false,
},
starts_at: {
type: DataTypes.DATE,
allowNull: false,
},
ends_at: {
type: DataTypes.DATE,
allowNull: false,
},
service_boundary_url: {
type: DataTypes.STRING,
allowNull: false,
},
service_boundary_updated: {
type: DataTypes.DATE,
allowNull: false,
},
created_at: {
type: DataTypes.DATE,
allowNull: false,
},
updated_at: {
type: DataTypes.DATE,
allowNull: false,
},
active: {
type: DataTypes.BOOLEAN,
allowNull: false,
defaultValue: false
}
});
};
note: i have defined an id field previously, and removed it in an attempt to resolve this issue. sync() is being called on server start.
However, calling create() is yielding this error:
{"name":"SequelizeDatabaseError","message":"null value in column \"id\" violates not-null constraint"
Any ideas why sequelize is expecting me to add my own ID value? This seems to be an issue that has floated up several times, but none of the proposed solutions have been working (autoIncrement:true, removing the ID field entirely)
Issue Analytics
- State:
- Created 8 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Postgres error: null value in column "id" - during insert operation
Since you don't explicitly set it, it's implicitly given a null value, which is, of course, not a valid value for a primary...
Read more >PostgreSQL Not-Null Constraint
We will introduce you to the NULL concept and how to use PostgreSQL not-null constraint to make sure that the values in columns...
Read more >NotNullViolation: ERROR: null value in column "id" violates ...
After migrating from 11.0.4 source to 11.0.4 omnibus on a new server everything seemed to work fine. Then we went the long upgrade...
Read more >PostgreSQL - NOT NULL Constraint - GeeksforGeeks
PostgreSQL Not-Null constraint as the name suggests is used to ensure that any value in the respective column is not null.
Read more >An id of null throws violates not-null constraint. #142 - GitHub
Running the following command in psql gives me the same error: postgres=> INSERT INTO "User" (id, email, hash, role) postgres-> VALUES (null, ' ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Resolved.
My issue was having created the tables initially with ID having been set to Integer (this is because of using sequelize-auto). Therefore, any future changes I made to the table were not occuring because sync() does not touch tables if they already exist.
Therefore, I had to call sync({force: true}) to get it to rewrite my table schema.
Sorry; it isn’t too large a project, though. Only a few routes defined and next to zero assets to pull down.
Getting it going should just be
npm install; node app.jsThen navigate to
/menus/createand fill in some garbage data.The relevant files are
/controllers/menus.js,/views/create.jade,/models/menu.js.