I have this class:
class BookUnitQuestionSchema extends Schema {
up () {
this.create('book_unit_question', (table) => {
table.increments()
table.integer('book_unit_id').references('id').inTable('book_unit')
table.string('correct_answer_description')
table.boolean('status').defaultTo(false)
table.integer('user_id').references('id').inTable('users')
table.timestamps()
})
}
down () {
this.drop('book_unit_question')
}
}
I need to change the data type of the column correct_answer_description
to text
.
If i change my actually up()
method to:
table.text('correct_answer_description')
and make a: adonis migration:refresh
All table is recreated and i lose the data in this table.
How i can only change the datatype without lose the data?
I try something like:
this.alter('book_unit_question', (table) => {
table.text('correct_answer_description')
})
And make a:
adonis migration:run
But i get:
Nothing to migrate
You need to create a new migration file like :
Type modification (new migration file) : .alter()
class BookUnitQuestionSchema extends Schema {
up() {
this.alter('book_unit_questions', (table) => {
table.text('correct_answer_description').notNullable().alter();
})
}
// reverse modification
down() {
this.table('book_unit_questions', (table) => {
table.string('correct_answer_description').notNullable().alter();
})
}
}
and run pending migrations :
> adonis migration:run
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