In the past, the project did not use the form of Classification Library, so the migration was very smooth, and there was no situation
The project is a little big this time, so we have to classify the library to facilitate the development and maintenance
An exception occurred while enabling project entityframework migration in the solution
Exception said that the dbcontext class was not found in my project
This dbcontext class is not really placed under the startup project, but a separate class library is established to store it
It was referenced in the startup project but could not be found
Check the get help enable migrations help and find that the enable migration command takes several parameters
Enable-Migrations [-ContextTypeName < String>] [- EnableAutomaticMigrations] [-ProjectName < String>] [- StartUpProjectName < String>] [- ConnectionStringName < String>] [- Force] [< CommonParameters>]
Contexttypename: the class name that the project inherits from dbcontext
Enable automatic migrations: enables automatic migration
ProjectName: the name of the project where the dbcontext class is stored
Startupprojectname: the name of the startup project in the solution. It is used to call the connection string under the project
Connectionstringname: connection string name
The above five parameters are necessary to solve the problem, and the others are irrelevant
For example:
Enable-Migrations -ContextTypeName “DBAccessLib.TJSSDBContext” -ProjectName “DBAccessLib” -StartUpProjectName “WebSite” -ConnectionStringName “TJSSDBContext” -Verbose
After filling in the order, the problem is solved
Similarly, you need to fill in the corresponding parameters when you add migration or update database. Otherwise, the same error will occur
For example:
Add-Migration -Name “EditCST_ DevicePhoto” -ProjectName “DBAccessLib” -StartUpProjectName “WebSite” -ConnectionStringName “TJSSDBContext” -Verbose
Update-Database -Script -ProjectName “DBAccessLib” -StartUpProjectName “WebSite” -ConnectionStringName “TJSSDBContext” -Verbose
Similar Posts:
- efcore Add-Migration Error Solved (Three Errors to Solved)
- [Solved] NodeNotFoundError(self.error_message, self.key, origin=self.origin) django.db.migrations.excep
- [Solved] VS Error: No project was found. Change the current working directory or use the –project option.
- The model backing the ‘XXX’ context has changed [Solved]
- Solutions to typeerror: expected string or bytes like object error
- [Solved] django.db.utils.ProgrammingError: (1146, u”Table” xxx doesn’t exist”)
- [Solved] You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for…
- Solution of kibana starting error reporting server is not ready yet
- [Solved] DjangoORM Run python manage.py makemigrations Error: no changes detected
- [Solved] Djiango Create Migrations Error: query = query.decode(errors=’replace’) AttributeError: ‘str’ object has no attribute ‘decode’