.NET Core OnModelCreating gives me error
Hi, ive always used this code but now the highlighted code crashed the Update-Database when I try to Add-Migration and Update-Database. If I remove the highlighted code it works. I cant see whats wrong here, is it something new with .NET 8 that makes it not work?
12 Replies
Im trying to creating two roles in the context, using Identity
Unknown User•4d ago
Message Not Public
Sign In & Join Server To View
If you have no further questions, please use /close to mark the forum thread as answered
how do I open it again?
Unknown User•3d ago
Message Not Public
Sign In & Join Server To View
The error is because you are seeding data with
Guid.NewGuid()
. This means that when OnModelCreate
runs the guid will be different every time (i believe a similar issue can happen when using DateTime.Now).
If this is an existing code base (or if too lazy - if its a personal project) then you can simply suppress the error and fix later. If possible though you should change the seed data to use an explicit non changing GUID.Unknown User•3d ago
Message Not Public
Sign In & Join Server To View
Just confused, are you saying that you think hardcoding the GUID is bad practice or using GUIDs as ids?
Unknown User•3d ago
Message Not Public
Sign In & Join Server To View
ah, i agree. Its also more performant than GUIDs during scanning but meh people like the GUIDs as Ids - more power to them
Unknown User•3d ago
Message Not Public
Sign In & Join Server To View