Currently, I am working to update/modify columns order by modifying code in ef core 6 project only. I have researched and found annotation [Column(order=0)] or [Column(order=1)] ... . But exactly if it works only first migration, for the next migrations by modifying column order in the model, the database doesn't update the following migration.
Model at first:
public class Student
{
[Column(Order=0)]
public int Id {get; set;}
[Column(Order = 1)]
public string Name {get; set;}
[Column(Order = 2)]
public DateTime Created_at {get; set;}
}
+----+------+------------+
| Id | Name | Created_at |
+----+------+------------+
After I add the new property "Age" into the model by setting column order=2 and "Created_at" 's order=3 but in the database, it displays "Age" at the last which is not my expectation.
Latest Model:
public class Student
{
[Column(Order=0)]
public int Id {get; set;}
[Column(Order = 1)]
public string Name {get; set;}
[Column(Order = 2)]
public int Age {get; set;}
[Column(Order = 3)]
public DateTime Created_at {get; set;}
}
+----+------+------------+-----+
| Id | Name | Created_at | Age |
+----+------+------------+-----+
While expectation is:
+----+------+-----+------------+
| Id | Name | Age | Created_at |
+----+------+-----+------------+
Provider and version information
Database provider: Pomelo.EntityFrameworkCore.MySql
Target framework: .NET 6.0
IDE: Visual Studio 2019 16.3