简体   繁体   English

书架和Knex SQLITE_ERROR:在“(”附近:

[英]Bookshelf and Knex SQLITE_ERROR: near “(”:

This is my console and the error it logs. 这是我的控制台及其记录的错误。 I'm trying to write a script (createDB.js) to populate the database with listings. 我正在尝试编写一个脚本(createDB.js),以使用清单填充数据库。 I'm stumped as to why I'm getting an SQLITE_ERROR. 我很困惑为什么我得到一个SQLITE_ERROR。

$ backend node createDB.js
listing:  ModelBase {
  attributes:
   { icon: 'pin',
     title: 'Hatsushiba',
     category: 'station',
     lat: 1.213,
     lng: 1.452 },
  _previousAttributes: {},
  changed:
   { icon: 'pin',
     title: 'Hatsushiba',
     category: 'station',
     lat: 1.213,
     lng: 1.452 },
  relations: {},
  cid: 'c1' }
error Error: insert into  (`category`, `created_at`, `icon`, `lat`, `lng`, `title`, `updated_at`) values ('station', '2018-06-28 10:52:27.520', 'pin', 1.213, 1.452, 'Hatsushiba', '2018-06-28 10:52:27.520') - SQLITE_ERROR: near "(": syntax error

createDB.js createDB.js

const Listing = require('./model')
const testListing = new Listing()
testListing.set('icon', 'pin')
testListing.set('title', 'Hatsushiba')
testListing.set('category', 'station')
testListing.set('lat', 1.213)
testListing.set('lng', 1.452)

testListing.save().then((listing) => {
  console.log(`saved ${listing.title} yo!`)
}).catch((err) => {
  console.log(`error ${err}`)
})

./migrate/index.js ./migrate/index.js

exports.up = function(knex) {
  return knex.schema
    .createTable('listings', function(table) {
      table.increments('id').primary()
      table.string('icon').defaultTo('pin')
      table.string('title', 128)
      table.string('category')
      table.float('lat')
      table.float('lng')
      table.timestamps()
    })
}

exports.down = function(knex) {
  return knex.schema
    .dropTable('listings')
}

model.js const bookshelf = require('./bookshelf') model.js const书架= require('./ bookshelf')

const Listing = bookshelf.Model.extend({
  tablename: 'listings',
  hasTimestamps: true
})

module.exports = Listing

knexfile.js knexfile.js

module.exports = {
  client: 'sqlite3',
  connection: {
    filename: 'app.db'
  },
  useNullAsDefault: true
}

bookshelf.js bookshelf.js

const path = require('path'),
      fs = require('fs'),
      knex = require('knex')(require('./knexfile'))

module.exports =  require('bookshelf')(knex)

in model.js 在model.js中

const Listing = bookshelf.Model.extend({
  tablename: 'listings', <<====== change "tablename" to "tableName" =====<<
  hasTimestamps: true
})

module.exports = Listing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM