Search code examples
mysqlnestjstypeorm

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


When I set typeORM synchronize:true I get an [ExceptionHandler] ER_TABLE_EXISTS_ERROR: Table 'courses' already exists +3ms QueryFailedError: ER_TABLE_EXISTS_ERROR: Table 'courses' already exists Error, But when I make synchronize:false I dont get that error. But I need to use synchronize:true in order to get the database changes. Any way to fix this issue?


Solution

  • You may need to flush the table cache. For example:

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

    Also, you can try Dropping your database and then setting synchronize: true if you have that level of permission.