diff --git a/packages/core/database/src/fields/field.ts b/packages/core/database/src/fields/field.ts index 2d3498668..de4fca9fd 100644 --- a/packages/core/database/src/fields/field.ts +++ b/packages/core/database/src/fields/field.ts @@ -145,6 +145,12 @@ export abstract class Field { let sql; if (this.database.sequelize.getDialect() === 'sqlite') { sql = `SELECT * from pragma_table_info('${this.collection.model.tableName}') WHERE name = '${this.name}'`; + } else if (this.database.inDialect('mysql')) { + sql = ` + select column_name + from INFORMATION_SCHEMA.COLUMNS + where TABLE_SCHEMA='${this.database.options.database}' AND TABLE_NAME='${this.collection.model.tableName}' AND column_name='${this.name}' + `; } else { sql = ` select column_name diff --git a/packages/plugins/collection-manager/src/server.ts b/packages/plugins/collection-manager/src/server.ts index 33ff5156c..d29277b16 100644 --- a/packages/plugins/collection-manager/src/server.ts +++ b/packages/plugins/collection-manager/src/server.ts @@ -77,11 +77,11 @@ export class CollectionManagerPlugin extends Plugin { } }); - this.app.db.on('fields.afterDestroy', async (model, options) => { + this.app.db.on('fields.beforeDestroy', async (model, options) => { await model.remove(options); }); - this.app.db.on('collections.afterDestroy', async (model, options) => { + this.app.db.on('collections.beforeDestroy', async (model, options) => { await model.remove(options); });