[英]Adonis js Drop column when migration:rollback
I am using adonis js to make a website.我正在使用adonis js制作网站。 I need to add certain columns to an existing table via migration and also drop those columns when I run "adonis migration:rollback".
我需要通过迁移将某些列添加到现有表中,并在运行“adonis migration:rollback”时删除这些列。 How do I write the migration down() function?
如何写下迁移()function?
The Code that I mention below for adonis make:migration medicines --action=select
我在下面提到的阿多尼斯代码
adonis make:migration medicines --action=select
'use strict'
/** @type {import('@adonisjs/lucid/src/Schema')} */
const Schema = use('Schema')
class MedicinesSchema extends Schema {
up () {
this.alter('medicines', (table) => {
// alter table
table.boolean('front_page');
table.integer( 'brand_id' ).nullable();
table.integer('offer_id').nullable();
})
}
down () {
this.table('medicines', (table) => {
// reverse alternations
// HOW DO I WRITE THE REVERSALS HERE ?
})
}
}
module.exports = MedicinesSchema
THANKS IN ADVANCE提前致谢
You can use dropColumn()
您可以使用
dropColumn()
knex.schema.table('users', function (table) {
table.dropColumn('name');
table.string('first_name');
table.string('last_name');
})
alter table `users` add `first_name` varchar(255), add `last_name` varchar(255);
alter table `users` drop `name`
down () {
this.table('medicines', (table) => {
table.dropColumn('myColumn');
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.