I want to update-database, but i see i first need to enable-migration first to the target database column
When i use this command on my console
Enable-Migrations
More than one context type was found in the assembly 'eNtsaRegistrationTraining'.
To enable migrations for 'eNtsaRegistrationTraining.Models.ApplicationDbContext', use Enable-Migrations -ContextTypeName eNtsaRegistrationTraining.Models.ApplicationDbContext.
To enable migrations for 'eNtsaRegistrationTraining.DAL.eNtsaRegCourses', use Enable-Migrations -ContextTypeName eNtsaRegistrationTraining.DAL.eNtsaRegCourses.
To enable migrations for 'eNtsaRegistrationTraining.DAL.eNtsaRegistration', use Enable-Migrations -ContextTypeName eNtsaRegistrationTraining.DAL.eNtsaRegistration.
PM> Enable-Migrations -ContextTypeName eNtsaRegistrationTraining.DAL.eNtsaCourses
The context type 'eNtsaRegistrationTraining.DAL.eNtsaCourses' was not found in the assembly 'eNtsaRegistrationTraining'.
I only need eNtsaCourses one, how can i resolve this issue with command console?
Enable-Migrations -ContextTypeName eNtsaRegistrationTraining.DAL.eNtsaRegCourses -force
Related
I have a project call RemoteWork where i have my Dbcontext. I have 2 models inside the DbContext - USER and PRODUCTS. I was using code first approach. I then used the "add-migration" and it was successful. I then referenced the Remotework in another project call Apiclient. They are both in the same solution. Now I have altered my table in USER and so it was out of sync. I wanted to make it to be in sync. I have tried different methods i have read online, I was getting different error messages. Can anyone please help in this regard.
I have done this: Add-Migration SecondMigration
This is the error message:
No DbContext was found in assembly 'AppClient'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
Please note that AppClient was made as the startup project. I have also tried making remotework as a start up project, it did not resolve it either:
PM> Add-Migration SecondMigration
No DbContext was found in assembly 'AppClient'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.
PM> Add-Migration -Name MyMigration -OutputDir MyMigrationDir -Context BettingDbContext -Project RemoteWork -StartupProject AppClient
I wanted the models to be in sync with my database
I assume you are running add-migration from the package manager console in visual studio.
Either make sure you have selected the project that contains your context in the "Default project" dropdown at the top of the package manager console. Or use the -StartUpProjectName argument on add-migration.
Every time I want to update database with code-first migrations I need to open Package Manager Console, set up Default project to project where I have migrations and write command:
update-database -startupprojectname CoreConsole
How I can set up in my solution:
1) Default project in dropdown where migrations are stored
2) startupprojectname where config with connection settings is stored
The target is to only write command update-database in console without any parameters and additional dropdown selections.
I'm trying to run a add-migration via my .net MVC project. There are two DBContext in a DBContext folder. However, when I run the command:
add-migration -ConfigurationTypeName xxxxx.Configuration -Name SavedSearches
it tells me:
The migrations configuration type 'xxxxx.Configuration' was not be found in the assembly 'xxxxx'.
Where do I find the proper name/namespace for the configuration type (i.e. what folder is it in, what level)? I've tried to search, but nothing clearly states it out.
Thank you.
From the Tools menu, click Library Package Manager and then Package Manager Console.
At the PM> prompt enter the following commands:
enable-migrations
add-migration InitialCreate
update-database
Following this Microsoft Tutorial when I run the PM> Add-Migration MyFirstMigration command in VS2015 project created from the same tutorial I get the following error that I can't resolve:
More than one DbContext was found. Specify which one to use.
Use the '-Context' parameter for PowerShell commands and the
'--context' parameter for dotnet commands.
Point to note
I'm using the above tutorial with the exception that I'm using Individual User Account authentication instead of No Authentication used in the tutorial.
I've latest release of ASP.NeT Core 1.0 and VS2015-Update 3 on windows 8.1
This is a freshly created project. No other DbContext was manually installed
Running the following command (obtained from this article) and a response from #Maverik (from StackOverflow here) and a suggestion from #doctor above helped me resolved the issue. Thank you all for your help:
PM> Add-Migration MyFirstMigration -Context BloggingContext
The error clearly explains to mention --context with db Context name if more than one DbContext. So try by mentioning your DbContext name.
dotnet ef migrations add Initial --context SampleDbContext
Hope this helps.
If you need only update a identity schema existent, try it:
update-database -Context ApplicationDbContext
ApplicationDbContext = your identity context
that because you have two DbContext in your solution. First is default created when you creating project(ApplicationDbContext) and second your EF DbContext.
Solution is described in error message just specify your EF DbContext
Add-Migration MyFirstMigration -Context DbContextName
It does work in my project.
Use below to commands:
PM> Add-Migration MyFirstMigration -Context YourDbContext
PM> update-database -Context YourDbContext
[--context]
The DbContext class to use. Class name only or fully qualified with
namespaces. If this option is omitted, EF Core will find the context
class. If there are multiple context classes, this option is required.
Add-Migration MyMigration -context DataContextName
I removed the data annotation Required from a field. Do I need to use migrations to apply that in the DB? If yes, how can I do that?
To add a migration you go to the Package Manager Console
Run command -> Enable-Migrations
Run command -> add-migration [migration_name]
Run command -> update-database
To apply on production database you can create a script in the following manner
Update-Database -Script -SourceMigration:[NameOfMigrationYourDatabaseIsRunning]
run
update-database -verbose
in the package manager console