You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
I try to create my database with migrations. My database context is a separate class library. When I call
dotnet ef database update --startup-project ../SpecialInspection/
I get the following error:
42704: type "inspection_value_type" does not exist
Here is my code:
public class SpecialInspectionContext : DbContext
{
public SpecialInspectionContext(DbContextOptions<SpecialInspectionContext> options)
: base(options)
{
}
public DbSet<InspectionValue> InspectionValues { get; set; } = null!;
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
NpgsqlConnection.GlobalTypeMapper.MapEnum<InspectionValueType>();
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("special_inspection");
modelBuilder.HasPostgresEnum<InspectionValueType>();
modelBuilder.Entity<InspectionValue>().Property(i => i.Id).UseIdentityAlwaysColumn();
modelBuilder.Entity<InspectionValue>().HasIndex(i => new {i.Type, i.Value}).IsUnique();
}
}
public enum InspectionValueType
{
Customer,
LockingSystem,
Article,
Order
}
public InspectionValue(string value, InspectionValueType type, DateTime createdAt, string createdBy)
{
Value = value;
Type = type;
CreatedAt = createdAt;
CreatedBy = createdBy;
}
public InspectionValue(int id, string value, InspectionValueType type, DateTime createdAt, string createdBy)
{
Id = id;
Value = value;
Type = type;
CreatedAt = createdAt;
CreatedBy = createdBy;
}
[Key]
public int? Id { get; set; }
[Required]
public string Value { get; set; }
[Required]
public InspectionValueType Type { get; set; }
[Required]
public DateTime CreatedAt { get; set; }
[Required]
public string CreatedBy { get; set; }
}
public class DesignTimeContextFactory : IDesignTimeDbContextFactory<SpecialInspectionContext>
{
public SpecialInspectionContext CreateDbContext(string[] args)
{
var basePath = Directory.GetCurrentDirectory();
var environmentName = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
var configuration = new ConfigurationBuilder()
.SetBasePath(basePath)
.AddJsonFile($"{basePath}/../SpecialInspection/appsettings.json")
.AddJsonFile($"{basePath}/../SpecialInspection/appsettings.{environmentName}.json", true)
.Build();
var builder = new DbContextOptionsBuilder<SpecialInspectionContext>().UseNpgsql(configuration.GetConnectionString("Postgres"));
return new SpecialInspectionContext(builder.Options);
}
}
The text was updated successfully, but these errors were encountered:
We unfortunately have some issues with enums created in non-default schemas. As a workaround, you can edit the generated SQL migration script and add the schema, or specifically create the enum in the public schema.
Hi,
I try to create my database with migrations. My database context is a separate class library. When I call
I get the following error:
Here is my code:
The text was updated successfully, but these errors were encountered: