In the mvc5 application, I created the CodeFirst data model and performed several migrations on it.
Then I reorganized my project and moved all the data / migration classes to a new project that my presentation level refers to.
dbcontext successfully connects and performs read / write operations in the database after changing the project.
When I made minor changes to the model and started it add-migration, EF created a migration with code to create the database from the very beginning, for example, it did not "see" the existing tables.
Of course, when I ran
Get-Migrations -ConfigurationTypeName ConfigurationDbContext
I got
No migrations have been applied to the target database.
__MigrationHistorythe database is untouched, and the namespaces of the migration / configuration classes have not changed. Also, apparently, ConnectionString is in order, otherwise it will be difficult for him to work with db, and I will get "The model that supports the context has changed since the database was created" or a similar error.
EDIT:
As pointed out in the comment, I am specifying the exact connection string in the DbContext constructor, and not the connectionstirng name in web.config, as it was in the original mvc project.
There is still no history / change in db when running Get-Migrations and update-databse.
when i run Get-Migrations -ConfigurationTypeName My_Namespace.Migrations.ConfigurationDbContext.ConfigurationDbContext
I get
No migrations have been applied to the target database.
If I try to specify a connection string
Get-Migrations -ConfigurationTypeName My_Namespace.Migrations.ConfigurationDbContext.ConfigurationDbContext -ConnectionString "Server=my_server;Initial Catalog=my_catalog;User Id=my_user;Password=my_pass" -ConnectionProviderName="System.Data.SqlClient" -verbose -debug
PM stuck on the sign >>until I restarted or cleared the window ...
If I omitted ConnectionProviderName="System.Data.SqlClient", the console will ask me to enter it, and after input, it shows a connection with the correct db,
Target database is: 'my_catalog (DataSource: my_server Provider: System.Data.SqlClient, Origin: Explicit)
but still no migrations ...
No migrations have been applied to the target database.
/ ?
2:
dbcontext :
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base(
"Server=my_server_name;Initial Catalog=my_db_name;UserId=my_username;Password=my_password"
)
{}
public DbSet<Model1> Model1Entities { get; set; }
public DbSet<Model2> Model2Entities { get; set; }
public DbSet<Model3> Model3Entities { get; set; }
}
IdentityDbContext, mvc5 applicaiton, dbcontext.
ConfigurationDbContext -
internal sealed class ConfigurationDbContext : DbMigrationsConfiguration<ApplicationDbContext>
{
public ConfigurationDbContext()
{
AutomaticMigrationsEnabled = false;
}
protected override void Seed(ApplicationDbContext context)
{
}
}
!