knex migration create type for enum 抛出类型已经存在
knex migration creat type for enum thows type already exists
我正在尝试更改 table 中的一列以将 knex 枚举修改为本机类型以利用 Postgres 的类型系统,当我执行迁移时出现此错误类型 "request_type" already exists
, 知道这里发生了什么吗?
export async function up(knex: Knex): Promise<any> {
return knex.schema.alterTable('appointments', table => {
table.enu('type', ['video', 'physical'], { useNative: true, enumName: 'request_type' }).alter();
});
}
export async function down(knex: Knex): Promise<any> {
return knex.schema
.alterTable('appointments', table => {
table.dropColumn('type');
})
.then(() => knex.raw('CREATE TYPE request_type AS ENUM("video", "physical")'))
.then(() => knex.raw('drop type request_type'));
}
knex 中似乎存在错误,导致在像那样更改列时添加两次创建类型查询。
https://runkit.com/embed/xqtl8p2knhi8
const Knex = require('knex');
const knex = Knex({
client: 'pg',
});
knex.schema.alterTable('appointments', table => {
table.enu('type', ['video', 'physical'], { useNative: true, enumName: 'request_type' }).alter();
}).toSQL()
/*
Creates SQL:
0: Object {bindings: [], sql: "create type \"request_type\" as enum ('video', 'physical')"}
1: Object {bindings: [], sql: "create type \"request_type\" as enum ('video', 'physical')"}
2: Object {bindings: [], sql: "alter table \"appointments\" alter column \"type\" drop default"}
3: Object {bindings: [], sql: "alter table \"appointments\" alter column \"type\" drop not null"}
4: Object {bindings: [], …}
*/
我正在尝试更改 table 中的一列以将 knex 枚举修改为本机类型以利用 Postgres 的类型系统,当我执行迁移时出现此错误类型 "request_type" already exists
, 知道这里发生了什么吗?
export async function up(knex: Knex): Promise<any> {
return knex.schema.alterTable('appointments', table => {
table.enu('type', ['video', 'physical'], { useNative: true, enumName: 'request_type' }).alter();
});
}
export async function down(knex: Knex): Promise<any> {
return knex.schema
.alterTable('appointments', table => {
table.dropColumn('type');
})
.then(() => knex.raw('CREATE TYPE request_type AS ENUM("video", "physical")'))
.then(() => knex.raw('drop type request_type'));
}
knex 中似乎存在错误,导致在像那样更改列时添加两次创建类型查询。
https://runkit.com/embed/xqtl8p2knhi8
const Knex = require('knex');
const knex = Knex({
client: 'pg',
});
knex.schema.alterTable('appointments', table => {
table.enu('type', ['video', 'physical'], { useNative: true, enumName: 'request_type' }).alter();
}).toSQL()
/*
Creates SQL:
0: Object {bindings: [], sql: "create type \"request_type\" as enum ('video', 'physical')"}
1: Object {bindings: [], sql: "create type \"request_type\" as enum ('video', 'physical')"}
2: Object {bindings: [], sql: "alter table \"appointments\" alter column \"type\" drop default"}
3: Object {bindings: [], sql: "alter table \"appointments\" alter column \"type\" drop not null"}
4: Object {bindings: [], …}
*/