Before:
public class MyEntity
{
public string Id { get; set; }
//...
}
Config:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
//...
modelBuilder.Entity<MyEntity>()
.Property(e => e.Id)
.ValueGeneratedOnAdd();
}
This was the previous developer's code which resulted in GUID values for the column. But in C# I had to deal with strings, so I decided to change the model.
After:
public class MyEntity
{
public Guid Id { get; set; }
//...
}
And I removed the ValueGeneratedOnAdd()
code from Fluent API config.
I get the column "Id" cannot be cast automatically to type uuid
error.
I think the key in this message is the automatically
word.
Now my question is that since the values on that column are already GUID/UUID, is there any way to tell Postgres to change the varchar
type to uuid
and cast the current string value to UUID and put it in the column? I'm guessing there should be a SQL script that can do this without any data loss.