这是我的迁移文件的样子:
exports.up = (knex,Promise) => { return Promise.all([ knex.schema.createtableIfNotExists('users',(table) => { table.uuID('ID').primary() table.string('username',35) table.text('pword').notNullable() table.string('first_name',55) table.string('last_name',55) knex.schema.raw('coordinates POINT DEFAulT POINT (37.3875,-122.0575)') table.timestamp('date_created').defaultTo(knex.fn.Now()) }) ])}exports.down = (knex,Promise) => { return Promise.all([ knex.schema.droptableIfExists('users') ])}
这是失败的代码行:
knex.schema.raw('coordinates POINT DEFAulT POINT (37.3875,-122.0575)')
我也尝试删除schema属性:
knex.raw('coordinates POINT DEFAulT POINT (37.3875,-122.0575)')
没有打印出错误,它似乎无声地失败.
编辑1:
我用以下方法打印出来:knex.schema.raw(‘坐标POINT DEFAulT POINT(37.3875,-122.0575)’).然后(data => console.log(data)).catch(error => console.log(错误))
{ error: coordinates POINT DEFAulT POINT (37.3875,-122.0575) - Syntax error at or near "coordinates" at Connection.parseE (/Users/james/plural/backend-development/node_modules/pg/lib/connection.Js:554:11) at Connection.parseMessage (/Users/james/plural/backend-development/node_modules/pg/lib/connection.Js:381:17) at Socket.<anonymous> (/Users/james/plural/backend-development/node_modules/pg/lib/connection.Js:117:22) at emitOne (events.Js:96:13) at Socket.emit (events.Js:188:7) at readableAddChunk (_stream_readable.Js:172:18) at Socket.Readable.push (_stream_readable.Js:130:10) at TCP.onread (net.Js:542:20) name: 'error',length: 92,severity: 'ERROR',code: '42601',detail: undefined,hint: undefined,position: '1',internalposition: undefined,internalquery: undefined,where: undefined,schema: undefined,table: undefined,column: undefined,dataType: undefined,constraint: undefined,file: 'scan.l',line: '1081',routine: 'scanner_yyerror' }解决方法 试试这个:
table.specificType(‘coordinates’,’POINT’).defaultTo(knex.raw(‘POINT(37.3875,-122.0575)’))
对于Knex未涵盖的sql类型,您始终可以使用以下格式:
table.specificType(‘column_name’,’TYPE’)
总结以上是内存溢出为你收集整理的postgresql – Knex在Postgres中创建POINT数据类型全部内容,希望文章能够帮你解决postgresql – Knex在Postgres中创建POINT数据类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)