TypeORM throws QueryFailedError ER_TABLE_EXISTS_ERROR: Table 'courses' already exists in MySQL

TypeORM throws QueryFailedError ER_TABLE_EXISTS_ERROR: Table 'courses' already exists in MySQL

当我设置 typeORM synchronize:true 时,我得到一个 [ExceptionHandler] ER_TABLE_EXISTS_ERROR: Table 'courses' already exists +3ms QueryFailedError: ER_TABLE_EXISTS_ERROR: Table 'courses' already exists 错误, 但是当我制作 synchronize:false 时,我没有得到那个错误。 但是我需要使用 synchronize:true 来获取数据库更改。 有什么办法可以解决这个问题?

您可能需要刷新 table 缓存。例如:

DROP TABLE IF EXISTS `tablename` ;
FLUSH TABLES `tablename` ; /* or exclude `tablename` to flush all tables */
CREATE TABLE `tablename` ...

此外,您可以尝试删除您的数据库,然后设置 synchronize: true 如果您有该级别的权限。