Page 1 of 1

Type changes on migration

Posted: Thu 16 Dec 2021 10:45
by dgunseli
Hello all,

We are switching to Dotconnect for PostgreSQL from another provider (NpgSQL). We already have a live environment which built by migrations. After switching to Dotconnect for PostgreSQL migrations starts to generate type changes for existing entities like using varchar data type instead of text. It causes problems for migrations, especially for live production environment.

Now, we are curious about if there is a way to specify target data type for all specific data types. Instead of setting all entity fields with data annotation we want to use a specific database type for a data type (for example, text for all string fields)

Regards

Re: Type changes on migration

Posted: Mon 20 Dec 2021 17:53
by Shalex
Please specify the version of Entity Framework you are working with (e.g.: EF 6, EF Core 5, etc).

With EF 6, try using conversion:

Code: Select all

public class MyContext : DbContext {
 
    protected override void OnModelCreating(DbModelBuilder modelBuilder) {
 
      modelBuilder
        .Properties()
        .Where(p => p.PropertyType == typeof(string))
        .Configure(p => p.HasColumnType("text"));
    }
 
    // ...
  }