On the page "Work with SQL Server LocalDB in ASP.NET Core" in the section "Add the seed initializer" it should state to replace the contents of Program.cs with the following code. This might be obvious to more experienced individuals but not so to beginners.
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
@Stumpy842 agreed.
This part was causing errors for me: saying that Movie object already exists. When I deleted the dbo.Movie object problem was fixed. Later on I realized I don't need that part of the code since it trying to migrate the database again:
var context = services.GetRequiredService
context.Database.Migrate();
just delete this 2 lines of code and it works just fine.
In Razor Pages tutorial, that was pointed out, exactly as you said it. My chosen workaround was also to delete the dbo.Movie table (while I was following the Razor Pages tutorial). Good catch, by the way. Kudos!
I forgot to mention, when encountering the same error, the other fix is to stop IIS Express, so this will 'force' the recreation of the table. I believe it is worth mentioning this, too. Just in case somebody does not like the idea of deleting the dbo.Movie table. I got this to work, without deleting the table, but stopping IIS Express.
the other fix is to stop IIS Express, so this will 'force' the recreation of the table. I believe it is worth mentioning this, too. Ju
Per the tutorial:
Force the app to initialize (call the methods in the Startup class) so the seed method runs. To force initialization, IIS Express must be stopped and restarted. You can do this with any of the following approaches: