I've got some Knex migration scripts that look like this:
'use strict';
exports.up = function (knex) {
return knex.schema
.hasTable('user')
.then(function (exists) {
if (!exists) {
knex
.schema
.createTable('user', function (table) {
table.increments('id').primary();
table.string('firstName');
table.string('lastName');
table.string('email');
table.string('password');
table.string('username');
})
.then(console.log('created user table'));
}
});
};
The first time I ran this script, it created a table, which was great, but then I noticed that the table was malformed (I had passed a wrong parameter.) So I manually deleted the created table from my database, along with the knex_migrations and knex_migrations_lock tables, and re-ran the migration command. Now, it tells me that all migrations have run, but I still don't see the table. What gives? Is there a piece of of config hiding somewhere that I need to delete?
add "return".
'use strict';
exports.up = function (knex) {
return knex.schema
.hasTable('user')
.then(function (exists) {
if (!exists) {
return knex // **** udpate
.schema
.createTable('user', function (table) {
table.increments('id').primary();
table.string('firstName');
table.string('lastName');
table.string('email');
table.string('password');
table.string('username');
})
.then(console.log('created user table'));
}
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With