Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
Secuela de error de inserción masiva con columna de polígono

Tengo el siguiente modelo con una columna de tipo polígono

 module.exports = { up: async (queryInterface, Sequelize) => { await queryInterface.createTable('p_zones', { id: { allowNull: false, autoIncrement: true, primaryKey: true, type: Sequelize.INTEGER }, points: { type: Sequelize.GEOMETRY('POLYGON') }, }); }, down: async (queryInterface) => { await queryInterface.dropTable('ZonePoints'); } };

Y cuando intento sembrar usando sequelize-cli con el comando npx sequelize-cli db:seed:all

 const polygon = { type: 'Polygon', coordinates: [ [ [10, 10], [20, 10], [20, 20], [10, 20], [10, 10], ], ], }; const data = [{ points: polygon }]; await queryInterface.bulkInsert('p_zones', data);

Obtuve el siguiente error:

 ERROR: Invalid value { type: 'Polygon', coordinates: [ [ [ 10, 10 ], [ 20, 10 ], [ 20, 20 ], [ 10, 20 ], [ 10, 10 ] ] ] }

¿Qué estoy haciendo mal?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Esto parece ser un problema abierto en github para Sequelize versión 6. Podría probar lo que Americas sugiere en GitHub , es decir

 await queryInterface.bulkInsert( 'p_zones', data, {}, { points: { type: Sequelize.GEOMETRY('POLYGON') } });

Aunque debo admitir que cuando ejecuté lo anterior contra una base de datos de postgres , obtuve el siguiente error:

 Executing (default): INSERT INTO "p_zones" ("points") VALUES (GeomFromText('POLYGON((10 10,20 10,20 20,10 20,10 10))')); (node:18964) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: function geomfromtext(unknown) does not exist at Query.formatError ...

Pero espero que sea solo un error debido a la versión particular de PostGIS que tengo.

Aparte, su inserción funciona bien si es una instrucción .bulkCreate en lugar de una .bulkInsert . Desafortunadamente, no sé cómo ejecutar un .bulkInsert sin definir primero todo el modelo. Cosas que podrías probar:

  1. Construya una consulta sin procesar y realice la inserción masiva de esa manera.
  2. Intente definir el modelo accediendo al objeto sequelize desde queryInterface.sequelize y luego haga un .bulkCreate , que no debería generar ningún error.
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!