Bug #90958 MySql.Data.EntityFrameworkCore has problem with migration after rename table

Submitted: 22 May 2018 4:27 Modified: 1 Jul 2019 19:17
Reporter: deng yakui Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:8.0.11 OS:Any
Assigned to: CPU Architecture:Any
Tags: MySql.Data

[22 May 2018 4:27] deng yakui
Description:
Migration failed for syntax error after rename table name from `Users` to `WebUsers`

More details to view in https://github.com/aspnet/EntityFrameworkCore/issues/12070

How to repeat:
1. add an entity class named 'Users',in the dbcontext,write follwing codes to config table name to 'Users'
```
modelBuilder.Entity<MyUser>().ToTable("Users").HasKey(u => u.Id);
```

2. apply migration will create a table named 'Users'

3. rename the table name to 'WebUesrs' in dbcontext
```
modelBuilder.Entity<MyUser>().ToTable("Users").HasKey(u => u.Id);
```
4. apply new migration will faild for syntax error.

 ALTER TABLE `Users` DROP CONSTRAINT `PK_Users`;
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      ALTER TABLE `Users` DROP CONSTRAINT `PK_Users`;

Suggested fix:
The following scripts is not allowing in mysql syntax when renaming a table,

ALTER TABLE `Users` DROP CONSTRAINT `PK_Users`;
[31 May 2018 11:53] Chiranjeevi Battula
Hello deng yakui,

Thank you for the bug report.
Verified based on internal discussion with dev's.

Thanks,
Chiranjeevi.
[1 Jul 2019 19:17] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET  6.10.9 and 8.0.18 release, and here's the changelog entry:

A syntax error was generated during an operation attempting to rename a
table that was previously migrated from code. Now, the primary key
constraint for an existing table can be dropped without errors when the
follow-on migration operation is performed.

Thank you for the bug report.

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.055 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.