Reputation: 2364
I'm trying to get started with Knex.js and I cant seem to get any migrations to work. When I run the command knex migrate:latest
the database only has the knex_migrations
table.
Am I doing something wrong?
module.exports = {
development: {
client: 'postgresql', //Also tried just 'pg'
connection: {
host: process.env.SERVER_HOST,
user: process.env.SERVER_USER,
password: process.env.SERVER_PASSWORD,
database: 'mika_personal'
}
}
}
'use strict'
exports.up = function(knex, Promise) {
knex.schema.createTable('blog_posts', function(table) {
table.increments('id').primary()
table.string('name', 75)
.index()
.unique()
.notNullable()
table.text('content')
table.integer('views')
table.timestamps()
})
}
exports.down = function(knex, Promise) {
knex.schema.dropTable('blog_posts')
}
Upvotes: 0
Views: 1281
Reputation: 146014
Add return
to the first line of both of your up and down functions so knex gets access to the promise that knex.schema.*
returns, then knex can use this to coordinate executing the migration. For example:
exports.down = function(knex, Promise) {
return knex.schema.dropTable('blog_posts')
}
Upvotes: 4