Saturday 13 January 2018

knexJs Help please

Hello I am starting to use knexjs with a basic sqllite3 configuration for development.Here is my knexfile.js:module.exports = { development: { client: 'sqlite3', connection: { filename: 'src/db/db.sqlite' }, migrations: { directory: 'src/db/migrations' }, seeds: { directory: 'src/db/seeds' } }, production: { client: 'pg', version: '7.2', connection: { host: '127.0.0.1', user: 'your_database_user', password: 'your_database_password', database: 'myapp_test' } } } Production is just dummy variables.I have followed the migrations and seeds instructions.here is my initial migration and seeds:exports.up = function (knex, Promise) { return knex.schema .createTable('countries', table => { table.increments(); table.string('name').notNullable(); }); }; exports.down = function (knex, Promise) { return knex.schema .dropTable('countries'); }; andconst countries = require('../fixtures/countries.json'); exports.seed = function (knex, Promise) { return Promise.resolve() .then(() => knex('countries').del()) .then(() => knex('countries').insert(countries)); }; When i run the migration and seeds I get a db.sqlite file. When i run the file sqlite viewer, my countries table is there and all the data. So far so good.However in my route everything goes too shit:app.get('/', (req, res, next) => { return knex.select().from('countries') .then(data => res.json(data)) .catch(next); }); I get the error: "message": "select * from countries - SQLITE_ERROR: no such table: countries",I am starting to lose my mind. Please help.

Submitted January 14, 2018 at 04:00AM by davidmdm

No comments:

Post a Comment