arnoldssss arnoldssss -3 years ago 195
Node.js Question

Insert in postgress directly works but with Sequalize it does not

I have a project in node js with sequalize connected to a database.

The issue I'm facing is that when I insert in the database directly works but in sequalize it says something like:

"Unhandled rejection SequelizeDatabaseError: el valor null para la columna «id_p» viola la restricción not null"

First table is persona, second is pasaporte. I have a one to one relationship

Persona

Contacto

Here the issue does not happen:

persona.create({ nombre: 'ArnoldoBazaldua', edad: '6' })


Here it does:

pasaporte.create({ pasaporte_num: '811545531', fidP2: '2' })


id_p in models:

Pasaporte:

"idP": {
type: Seq.INTEGER,
field: "id_p",
primaryKey: true,
autoIncrement: true,
allowNull: true,
unique: "pasaporte_pkey",
references: "public.persona",
referencesKey: "id_p"
},


In persona:

"idP": {
type: Seq.INTEGER,
field: "id_p",
primaryKey: true,
autoIncrement: true,
allowNull: false,
unique: "persona_pkey"
},


Foreing key in persona table:

enter image description here

Answer Source

Assuming that pasaporte.id_p is a foreign key to persona`, then

persona.createPasaport({ .... }

Also pasaporte.telefono is not defined.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download