Not able to drop the database
When I run command: dotnet ef database drop It throws an error:
Object name: 'MvcMovieContext'.
at Microsoft.EntityFrameworkCore.DbContext.get_InternalServiceProvider()
at Microsoft.EntityFrameworkCore.Infrastructure.AccessorExtensions.GetService[TService](IInfrastructure1 accessor) at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.DropDatabase(String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.DropDatabase.<>c__DisplayClass0_1.<.ctor>b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'MvcMovieContext'.
I'm a newbie to C# and .NET Core. I don't know what went wrong. But here is my workaround: do another migration. run the following command: dotnet ef migrations add SecondCreate dotnet ef database update
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 8b6b0b52-7b5b-2ff6-d8ff-17fe27e24306
- Version Independent ID: 46eed0b3-acc4-982a-2e97-b865020db702
- Content: Add a new field to an ASP.NET Core app
- Content Source: aspnetcore/tutorials/first-mvc-app-mac/new-field.md
- Product: aspnet-core
- GitHub Login: @Rick-Anderson
- Microsoft Alias: riande
@xiao-ai that's a misleading error message. It can fail for a variety of reason. Try again. IF that doesn't work, change the connection string so a new DB is created.