我想在我的ts项目中使用knex。迁移看起来像这样:
export async function up(knex: Knex): Promise<any> {
return knex.schema.createTable('first_table', (t) => {
t.integer('first_table_id').primary();
}).createTable('second_table', (t) => {
t.integer('id');
// simulation sql error, duplicate in this case.
t.integer('id').
})
}迁移已失败。我等待所有更改的事务回滚,但我已经成功创建了first_table。我不理解某些东西或Knex行为不正确?
发布于 2019-12-22 06:41:18
当mysql执行DDL查询时,它会执行隐式提交。因此,在每次创建表事务的查询之后,都会自动提交事务。
除了在运行迁移之前获取DB转储,并在迁移失败时恢复它之外,没有真正简单的方法可以绕过它。
https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html
例如,在mysql中,如果您执行以下操作:
* start transaction
* create table 1
* rollback表1仍将被创建,并且不会回滚任何内容,因为在mysql内部实际上是:
* start transaction
* create table 1
* implicit commit
* implicit start transaction for rollback query
* rollback of automatically started empty transactionhttps://stackoverflow.com/questions/59425666
复制相似问题