AspNetCore.Docs icon indicating copy to clipboard operation
AspNetCore.Docs copied to clipboard

Not able to drop the database

Open xiao-ai opened this issue 8 years ago • 1 comments

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.

xiao-ai avatar Jul 12 '18 22:07 xiao-ai

@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.

Rick-Anderson avatar Jul 12 '18 23:07 Rick-Anderson