node.js - single quote escape - sequelize migration -
i'm using nodejs sequelize orm , postgress database i'm creating enum column named education_level
in table using migration file below , enum value (bachelor's degree) has single quote , gives below error when try run migrations, thank helping!
migration file
'use strict'; module.exports = { up: function(queryinterface, sequelize) { return queryinterface.createtable('education', { id: { allownull: false, autoincrement: true, primarykey: true, type: sequelize.integer }, school: { type: sequelize.string }, degree: { type: sequelize.string }, field_of_study: { type: sequelize.string }, year_started: { type: sequelize.string(4) }, year_graduated: { type: sequelize.string(4) }, education_level: { type: sequelize.enum, values: ['diploma','bachelor\'s degree','master\'s degree','doctorate degree'], }, profile_id: { type: sequelize.integer, allownull: true }, createdat: { allownull: false, type: sequelize.date }, updatedat: { allownull: false, type: sequelize.date } }); }, down: function(queryinterface, sequelize) { return queryinterface.droptable('education'); } };
error
{ sequelizebaseerror: syntax error @ or near "s" migrate_1 | @ query.formaterror (/usr/src/app/node_modules/sequelize/lib/dialects/postgres/query.js:357:14) migrate_1 | @ query.<anonymous> (/usr/src/app/node_modules/sequelize/lib/dialects/postgres/query.js:88:19) migrate_1 | @ emitone (events.js:96:13) migrate_1 | @ query.emit (events.js:191:7) migrate_1 | @ query.handleerror (/usr/src/app/node_modules/pg/lib/query.js:108:8) migrate_1 | @ connection.<anonymous> (/usr/src/app/node_modules/pg/lib/client.js:171:26) migrate_1 | @ emitone (events.js:96:13) migrate_1 | @ connection.emit (events.js:191:7) migrate_1 | @ socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:109:12) migrate_1 | @ emitone (events.js:96:13) migrate_1 | @ socket.emit (events.js:191:7) migrate_1 | @ readableaddchunk (_stream_readable.js:176:18) migrate_1 | @ socket.readable.push (_stream_readable.js:134:10) migrate_1 | @ tcp.onread (net.js:563:20) migrate_1 | name: 'sequelizedatabaseerror', migrate_1 | message: 'syntax error @ or near "s"', migrate_1 | parent: migrate_1 | { error: syntax error @ or near "s" migrate_1 | @ connection.parsee (/usr/src/app/node_modules/pg/lib/connection.js:539:11) migrate_1 | @ connection.parsemessage (/usr/src/app/node_modules/pg/lib/connection.js:366:17) migrate_1 | @ socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:105:22) migrate_1 | @ emitone (events.js:96:13) migrate_1 | @ socket.emit (events.js:191:7) migrate_1 | @ readableaddchunk (_stream_readable.js:176:18) migrate_1 | @ socket.readable.push (_stream_readable.js:134:10) migrate_1 | @ tcp.onread (net.js:563:20) migrate_1 | name: 'error', migrate_1 | length: 90, migrate_1 | severity: 'error', migrate_1 | code: '42601', migrate_1 | detail: undefined, migrate_1 | hint: undefined, migrate_1 | position: '84', migrate_1 | internalposition: undefined, migrate_1 | internalquery: undefined, migrate_1 | where: undefined, migrate_1 | schema: undefined, migrate_1 | table: undefined, migrate_1 | column: undefined, migrate_1 | datatype: undefined, migrate_1 | constraint: undefined, migrate_1 | file: 'scan.l', migrate_1 | line: '1086', migrate_1 | routine: 'scanner_yyerror', migrate_1 | sql: 'create type "public"."enum_education_education_level" enum(\'diploma\', \'bachelor\'s degree\', \'master\'s degree\', \'doctorate degree\');' }, migrate_1 | original: migrate_1 | { error: syntax error @ or near "s" migrate_1 | @ connection.parsee (/usr/src/app/node_modules/pg/lib/connection.js:539:11) migrate_1 | @ connection.parsemessage (/usr/src/app/node_modules/pg/lib/connection.js:366:17) migrate_1 | @ socket.<anonymous> (/usr/src/app/node_modules/pg/lib/connection.js:105:22) migrate_1 | @ emitone (events.js:96:13) migrate_1 | @ socket.emit (events.js:191:7) migrate_1 | @ readableaddchunk (_stream_readable.js:176:18) migrate_1 | @ socket.readable.push (_stream_readable.js:134:10) migrate_1 | @ tcp.onread (net.js:563:20) migrate_1 | name: 'error', migrate_1 | length: 90, migrate_1 | severity: 'error', migrate_1 | code: '42601', migrate_1 | detail: undefined, migrate_1 | hint: undefined, migrate_1 | position: '84', migrate_1 | internalposition: undefined, migrate_1 | internalquery: undefined, migrate_1 | where: undefined, migrate_1 | schema: undefined, migrate_1 | table: undefined, migrate_1 | column: undefined, migrate_1 | datatype: undefined, migrate_1 | constraint: undefined, migrate_1 | file: 'scan.l', migrate_1 | line: '1086', migrate_1 | routine: 'scanner_yyerror', migrate_1 | sql: 'create type "public"."enum_education_education_level" enum(\'diploma\', \'bachelor\'s degree\', \'master\'s degree\', \'doctorate degree\');' }, migrate_1 | sql: 'create type "public"."enum_education_education_level" enum(\'diploma\', \'bachelor\'s degree\', \'master\'s degree\', \'doctorate degree\');' } api_migrate_1 exited code 1
you need escape single quote single quote. maybe work:
education_level: { type: sequelize.enum, values: ['diploma','bachelor\'\'s degree','master\'\'s degree','doctorate degree'], },
Comments
Post a Comment