I was running successfully Entity framework 6.0.0-alpha3
until today. Today I decided to update to Entity framework 6.0.0-rc1
, and as specified here in order to run my migrations I need to remove all the previous migrations made by ef alpha1-alpha3
and remake them.
Since all my migrations were made by alpha3
, I decided to drop all the migrations (including _MigrationHistory table), and re-enable it.
I created initial migration with add-migration Initial -IgnoreChanges
(which has empty Up()
and Down()
methods), then I executed update-database
, and I thought, that everything is okay. Well, its not. When I am adding new class to my model, add-migration first
creates migration with empty Up()
and Down()
methods.
Also, previously, when I wanted to access object that wasn't yet registered with migrations, I was receiving an error saying that I need to update my migrations. Now, when I try to access the new object, it simply says "Invalid object name 'dbo.Notifications'."
.
What do I do now?
The EF command-line tools can be used to apply migrations to a database. While productive for local development and testing of migrations, this approach isn't ideal for managing production databases: The SQL commands are applied directly by the tool, without giving the developer a chance to inspect or modify them.
Change Tracker. Detect Changes Method Microsoft. Entity Framework Core. Change Tracking Scans the tracked entity instances to detect any changes made to the instance data. DetectChanges () is usually called automatically by the context when up-to-date information is required (before SaveChanges () and when returning change tracking information).
Microsoft. EntityFrameworkCore. ChangeTracking Change Tracker. Detect Changes Method Microsoft. Entity Framework Core. Change Tracking Scans the tracked entity instances to detect any changes made to the instance data.
The steps for the first step are as follows (in ASP.net MVC Web Application with EF6): In your project (which should already be running with some models and in a consistent state), go to package manager console and run Enable-Migrations –EnableAutomaticMigrations.
This is because instances of the underlying entity type will not generate notifications, which means changes made to these entities will be missed. EF Core creates proxy instances automatically when querying the database, so this downside is generally limited to tracking new entity instances.
EF uses a snapshot of the database model (which is saved along with the migration) to determine changes between current version of your database model and the last migration.
add-migration Initial -IgnoreChanges
command creates a migration with the snapshot of your database model, but it ignores any changes from previous database snapshot (i.e. empty database) because you are telling to do so.
add-migration First
command looks at previous migration (i.e. Initial) and compares the current database model snapshot with the snapshot form the Initial
migration. Obviously these snapshots are the same, so Up()
and Down()
methods are empty.
I think the solution for your problem is to generate all changes in the Initial migration
add-migration Initial
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With