I 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 in node.js with sequelize version 1.4.1.
matched 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 copy 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)); })
the error i get
* Fulfillment: INSERT INTO "dead birth" ("state", "year", "account", "id") VALUES ("Andhra Pradesh", 2004,11, NULL) RETURN; Could not save line {"length": 110, "name": "error", "severity": "ERROR", "code": "23502", "file": "execMain.c", "line": " +1359 "," normal ":" ExecConstraints "}
If you look at the sql that generates it, it puts null for the primary key, which ideally should be generated by db.
Can someone help me with what I do not see here?