C
C#3mo ago
Antlin23

.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?
No description
13 Replies
Antlin23
Antlin23OP3mo ago
Im trying to creating two roles in the context, using Identity
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
MODiX
MODiX3mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Antlin23
Antlin23OP3mo ago
No description
Antlin23
Antlin23OP3mo ago
how do I open it again?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3mo ago
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
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3mo ago
Just confused, are you saying that you think hardcoding the GUID is bad practice or using GUIDs as ids?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
hippiewho
hippiewho3mo ago
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
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Antlin23
Antlin23OP2mo ago
sry for very late reply, changed to hardcoded guids and it works @hippiewho @TeBeCo

Did you find this page helpful?