Build started...
Build succeeded.
System.InvalidOperationException: An error was generated for warning
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning':
The model for context 'RepositoryContext' has pending changes. Add a
new migration before updating the database. This exception can be
suppressed or logged by passing event ID
'RelationalEventId.PendingModelChangesWarning' to the
'ConfigureWarnings' method in 'DbContext.OnConfiguring' or
'AddDbContext'.
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam arg)
at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.PendingModelChangesWarning(IDiagnosticsLogger`1 diagnostics, Type contextType)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Es wurde ein Fehler für die Warnung generiert
'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning':
Das Modell für den Kontext 'RepositoryContext' hat ausstehende Änderungen. Fügen Sie eine
neue Migration hinzu, bevor Sie die Datenbank aktualisieren. Diese Ausnahme kann
unterdrückt oder protokolliert werden, indem die Ereignis-ID
'RelationalEventId.PendingModelChangesWarning' an die Methode
'ConfigureWarnings' in 'DbContext.OnConfiguring' oder
'AddDbContext' übergeben wird.< /p>
Ich versuche, Seeding-Daten zu erstellen. Wenn ich „dotnet ef Database Update“ ausführe, erhalte ich die folgende Fehlermeldung: [code]Build started...
Build succeeded.
System.InvalidOperationException: An error was generated for warning 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': The model for context 'RepositoryContext' has pending changes. Add a new migration before updating the database. This exception can be suppressed or logged by passing event ID 'RelationalEventId.PendingModelChangesWarning' to the 'ConfigureWarnings' method in 'DbContext.OnConfiguring' or 'AddDbContext'.
at Microsoft.EntityFrameworkCore.Diagnostics.EventDefinition`1.Log[TLoggerCategory](IDiagnosticsLogger`1 logger, TParam arg) at Microsoft.EntityFrameworkCore.Diagnostics.RelationalLoggerExtensions.PendingModelChangesWarning(IDiagnosticsLogger`1 diagnostics, Type contextType) at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration) at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) [/code]
Es wurde ein Fehler für die Warnung generiert 'Microsoft.EntityFrameworkCore.Migrations.PendingModelChangesWarning': Das Modell für den Kontext 'RepositoryContext' hat ausstehende Änderungen. Fügen Sie eine neue Migration hinzu, bevor Sie die Datenbank aktualisieren. Diese Ausnahme kann unterdrückt oder protokolliert werden, indem die Ereignis-ID 'RelationalEventId.PendingModelChangesWarning' an die Methode 'ConfigureWarnings' in 'DbContext.OnConfiguring' oder 'AddDbContext' übergeben wird.< /p>
Mein RepositoryContext.cs ist: [code]using Entities.Models; using Entities.Models.Enums; using Microsoft.EntityFrameworkCore;
namespace Repositories { public class RepositoryContext : DbContext { public DbSet AgeGroups { get; set; }
public DbSet Hairdressers { get; set; } public DbSet HairdressingServices { get; set; }
public DbSet CustomerAppointments { get; set; } public DbSet HairdressingServiceLocalizations { get; set; }
public RepositoryContext(DbContextOptions options) : base(options) {
private void SeedingData(ModelBuilder modelBuilder) { var ageGroup1 = new AgeGroup { Id = 1, MinAge = 0, MaxAge = 17 }; var ageGroup2 = new AgeGroup { Id = 2, MinAge = 18, MaxAge = 75 }; var ageGroup3 = new AgeGroup { Id = 3, MinAge = 76, MaxAge = 125 }; var ageGroup = new List(); ageGroup.Add(ageGroup1); ageGroup.Add(ageGroup2);
var hairdressingService1 = new HairdressingService { Id = 1, Name = "HairCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 20, 0), Price = 100, Status = true }; var hairdressingService2 = new HairdressingService { Id = 2, Name = "RazorShave", Genders = { Gender.m }, Duration = new TimeSpan(0, 40, 0), Price = 200, Status = true }; var hairdressingService3 = new HairdressingService { Id = 3, Name = "HairColoring", Genders = { Gender.m }, Duration = new TimeSpan(0, 60, 0), Price = 300, Status = true }; var hairdressingService4 = new HairdressingService { Id = 4, Name = "BrowShaping", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 80, 0), Price = 400, Status = true }; var hairdressingService5 = new HairdressingService { Id = 5, Name = "BeardGrooming", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 100, 0), Price = 500, Status = true }; var hairdressingService6 = new HairdressingService { Id = 6, Name = "ChildShave", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 120, 0), Price = 600, Status = true }; var hairdressingService7 = new HairdressingService { Id = 7, Name = "PermHair", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 140, 0), Price = 700, Status = false }; var hairdressingService8 = new HairdressingService { Id = 8, Name = "Manicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 150, 0), Price = 800, Status = false }; var hairdressingService9 = new HairdressingService { Id = 9, Name = "Pedicure", Genders = { Gender.m, Gender.f }, Duration = new TimeSpan(0, 160, 0), Price = 900, Status = false }; var hairdressingService10 = new HairdressingService { Id = 10, Name = "GroomsCut", Genders = { Gender.m }, Duration = new TimeSpan(0, 180, 0), Price = 1000, Status = true }; var hairdressingService11 = new HairdressingService { Id = 11, Name = "Makeup(Bride)", Genders = { Gender.f }, Duration = new TimeSpan(0, 200, 0), Price = 1100, Status = false };
List hairdressingServices = new List(); hairdressingServices.Add(hairdressingService1); hairdressingServices.Add(hairdressingService2); hairdressingServices.Add(hairdressingService3); hairdressingServices.Add(hairdressingService4); hairdressingServices.Add(hairdressingService5); hairdressingServices.Add(hairdressingService6); hairdressingServices.Add(hairdressingService7); hairdressingServices.Add(hairdressingService8); hairdressingServices.Add(hairdressingService9); hairdressingServices.Add(hairdressingService10); hairdressingServices.Add(hairdressingService11);
var hairdresser1 = new Hairdresser { Id = 1, IdentityUserId = "1", Name = "Aydın", Surname = "Sevim", CanTakeClients = true }; var hairdresser2 = new Hairdresser { Id = 2, IdentityUserId = "2", Name = "Alpay", Surname = "Aydıngüler", CanTakeClients = true }; var hairdresser3 = new Hairdresser { Id = 3, IdentityUserId = "2", Name = "Deniz", Surname = "Dağ", CanTakeClients = false }; var hairdressers = new List(); hairdressers.Add(hairdresser1); hairdressers.Add(hairdresser2); hairdressers.Add(hairdresser3);
modelBuilder.Entity().HasData(ageGroup1, ageGroup2, ageGroup3); modelBuilder.Entity().HasData(hairdressingServices); modelBuilder.Entity().HasData(hairdressers); modelBuilder.Entity("HairdressingServiceAgeGroups").HasData( new { HairdressingServiceId = 1, AgeGroupsId = 1 }, new { HairdressingServiceId = 2, AgeGroupsId = 2 }, new { HairdressingServiceId = 3, AgeGroupsId = 1 }, new { HairdressingServiceId = 3, AgeGroupsId = 2 }, new { HairdressingServiceId = 4, AgeGroupsId = 1 }, new { HairdressingServiceId = 5, AgeGroupsId = 1 }, new { HairdressingServiceId = 5, AgeGroupsId = 2 }, new { HairdressingServiceId = 6, AgeGroupsId = 1 }, new { HairdressingServiceId = 7, AgeGroupsId = 2 }, new { HairdressingServiceId = 8, AgeGroupsId = 2 }, new { HairdressingServiceId = 9, AgeGroupsId = 2 }, new { HairdressingServiceId = 10, AgeGroupsId = 2 }, new { HairdressingServiceId = 11, AgeGroupsId = 2 } );
modelBuilder.Entity().HasData(// HairCut new HairdressingServiceLocalization { Id = 1, HairdressingServiceId = 1, Language = "en-GB", Name = "Hair Cut" }, new HairdressingServiceLocalization { Id = 2, HairdressingServiceId = 1, Language = "tr-TR", Name = "Saç Kesimi" }, // RazorShave new HairdressingServiceLocalization { Id = 3, HairdressingServiceId = 2, Language = "en-GB", Name = "Razor Shave" }, new HairdressingServiceLocalization { Id = 4, HairdressingServiceId = 2, Language = "tr-TR", Name = "Jilet Traşı" }, // HairColoring new HairdressingServiceLocalization { Id = 5, HairdressingServiceId = 3, Language = "en-GB", Name = "Hair Coloring" }, new HairdressingServiceLocalization { Id = 6, HairdressingServiceId = 3, Language = "tr-TR", Name = "Saç Boyama" }, // BrowShaping new HairdressingServiceLocalization { Id = 7, HairdressingServiceId = 4, Language = "en-GB", Name = "Brow Shaping" }, new HairdressingServiceLocalization { Id = 8, HairdressingServiceId = 4, Language = "tr-TR", Name = "Kaş Şekillendirme" }, // BeardGrooming new HairdressingServiceLocalization { Id = 9, HairdressingServiceId = 5, Language = "en-GB", Name = "Beard Grooming" }, new HairdressingServiceLocalization { Id = 10, HairdressingServiceId = 5, Language = "tr-TR", Name = "Sakal Bakımı" }, // ChildShave new HairdressingServiceLocalization { Id = 11, HairdressingServiceId = 6, Language = "en-GB", Name = "Child Shave" }, new HairdressingServiceLocalization { Id = 12, HairdressingServiceId = 6, Language = "tr-TR", Name = "Çocuk Tıraşı" }, // PermHair new HairdressingServiceLocalization { Id = 13, HairdressingServiceId = 7, Language = "en-GB", Name = "Perm Hair" }, new HairdressingServiceLocalization { Id = 14, HairdressingServiceId = 7, Language = "tr-TR", Name = "Perma Saç" }, // Manicure new HairdressingServiceLocalization { Id = 15, HairdressingServiceId = 8, Language = "en-GB", Name = "Manicure" }, new HairdressingServiceLocalization { Id = 16, HairdressingServiceId = 8, Language = "tr-TR", Name = "Manikür" }, // Pedicure new HairdressingServiceLocalization { Id = 17, HairdressingServiceId = 9, Language = "en-GB", Name = "Pedicure" }, new HairdressingServiceLocalization { Id = 18, HairdressingServiceId = 9, Language = "tr-TR", Name = "Pedikür" }, // GroomsCut new HairdressingServiceLocalization { Id = 19, HairdressingServiceId = 10, Language = "en-GB", Name = "Groom's Cut" }, new HairdressingServiceLocalization { Id = 20, HairdressingServiceId = 10, Language = "tr-TR", Name = "Damat Kesimi" }, // Makeup(Bride) new HairdressingServiceLocalization { Id = 21, HairdressingServiceId = 11, Language = "en-GB", Name = "Makeup (Bride)" }, new HairdressingServiceLocalization { Id = 22, HairdressingServiceId = 11, Language = "tr-TR", Name = "Makyaj (Gelin)" });
modelBuilder.Entity("HairdresserHairdressingServices").HasData( new { HairdresserId = 1, HairdressingServicesId = 1 }, new { HairdresserId = 1, HairdressingServicesId = 2 }, new { HairdresserId = 1, HairdressingServicesId = 3 }, new { HairdresserId = 1, HairdressingServicesId = 4 }, new { HairdresserId = 1, HairdressingServicesId = 5 }, new { HairdresserId = 2, HairdressingServicesId = 2 }, new { HairdresserId = 1, HairdressingServicesId = 6 }, new { HairdresserId = 1, HairdressingServicesId = 7 }, new { HairdresserId = 1, HairdressingServicesId = 8 }, new { HairdresserId = 1, HairdressingServicesId = 9 }, new { HairdresserId = 1, HairdressingServicesId = 10 } );
private void CustomerAppointmentSeedingData(ModelBuilder modelBuilder, List hairdressingServicesList, List hairdressersList, List ageGroups) { Console.WriteLine("Seeding CustomerAppointments..."); var random = new Random(); var customerAppointmentHairdressingServices = new List(); var customerAppointments = new List(); var statuses = Enum.GetValues(typeof(CustomerAppointmentStatus)).Cast().ToArray();
for (int i = 0; i < 1; i++) { // Select a random Hairdresser, AgeGroup, and Status var hairdresser = hairdressersList[random.Next(hairdressersList.Count)]; var ageGroup = ageGroups[random.Next(ageGroups.Count)]; var status = statuses[random.Next(statuses.Length)];
// Select 1 to 3 random HairdressingServices var selectedServices = hairdressingServicesList.OrderBy(x => random.Next()).Take(random.Next(1, 4)).ToList();
// Calculate the total duration by summing the durations of selected services TimeSpan totalDuration = selectedServices.Aggregate(TimeSpan.Zero, (sum, service) => sum.Add(service.Duration));
// Random DateTime within the next 30 days DateTime appointmentDateTime = DateTime.Now.AddDays(random.Next(1, 31)).AddHours(random.Next(9, 18)).AddMinutes(random.Next(0, 60));
// Create the CustomerAppointment entity var customerAppointment = new CustomerAppointment { Id = i + 1, Name = $"Name{i + 1}", Surname = $"Surname{i + 1}", Gender = (Gender)random.Next(0, 2), // Random gender (0 or 1) AgeGroupId = ageGroup.Id, HairdresserId = hairdresser.Id, Duration = totalDuration, Price = selectedServices.Sum(service => service.Price), DateTime = appointmentDateTime, PhoneNumber = $"+90 123 456 78{random.Next(10, 99)}", EMail = $"customer{i + 1}@example.com", CreatedBy = null, // Replace with actual IdentityUser if needed Status = status /* Id = i + 1, Name = $"Name", Surname = $"Surname", Gender = Gender.m, // Random gender (0 or 1) AgeGroupId = 1, HairdresserId = 1, Duration = new TimeSpan(0,20,0), Price = selectedServices.Sum(service => service.Price), DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)), PhoneNumber = $"+90 123 456 78 22", EMail = $"[email protected]", CreatedBy = null, // Replace with actual IdentityUser if needed Status = CustomerAppointmentStatus.AwaitingApproval */ };
customerAppointments.Add(customerAppointment);
// Seed the many-to-many relationship (CustomerAppointment HairdressingService) foreach (var service in selectedServices) { customerAppointmentHairdressingServices.Add( new { CustomerAppointmentId = customerAppointment.Id, HairdressingServicesId = service.Id } ); }
} } } [/code] Wenn ich alles so von Hand eingebe, funktioniert es: [code] Id = i + 1, Name = $"Name", Surname = $"Surname", Gender = Gender.m, // Random gender (0 or 1) AgeGroupId = 1, HairdresserId = 1, Duration = new TimeSpan(0,20,0), Price = 100, //selectedServices.Sum(service => service.Price), DateTime = new DateTime(new DateOnly(2025,1,1), new TimeOnly(13,30)), PhoneNumber = $"+90 123 456 78 22", EMail = $"[email protected]", CreatedBy = null, // Replace with actual IdentityUser if needed Status = CustomerAppointmentStatus.AwaitingApproval [/code] Aber wenn ich auch nur den Preis zurück ändere [code] Price = selectedServices.Sum(service => service.Price), [/code] Es wird der gleiche Fehler angezeigt. Was übersehe ich hier?
Ich arbeite an einer ASP.NET Core-Web-API mit Entity Framework Core. Als ich versuchte, meine Datenbank zu aktualisieren, erhalte ich diese Fehlermeldung:
Ich versuche, eine Tabelle mit einer JPQL -Abfrage in Spring Data JPA zu aktualisieren, aber ich begegne einen Fehler: Spalte 'is_deleted in der Feldliste ist mehrdeutig. Der Fehler tritt auf, da der...
Ich versuche, eine Tabelle mit einer JPQL -Abfrage in Spring Data JPA zu aktualisieren, aber ich begegne einen Fehler: Spalte 'is_deleted in der Feldliste ist mehrdeutig. Der Fehler tritt auf, da der...