Migrations - Existing Databases

Play Migrations - Existing Databases

The Discussion

  • User profile image

    Hi, I'm using VS2013 Prof. Edt. Upd. 1 (v12.0.30110.00) following step find this:

    - First, I update with NugGet Packages EF 5 to 6.1 (in .Net 4.0 and 4.5)... also try without this upgrade.

    - In second EF Model Wizard step always show just two options: Generate from datase and empty model.... not 

    - Model is created with different files than your video (.diagram, .tt with clases files related, .designer.cs, etc.)

    - My Package Manager Console Host use Version 2.8.50126.477 not 2.7.41101.371 like yours.

    - When I try to run Enable-Migrations -ContextTypeName MyModelName show me this:

    Creating a DbModelBuilder or writing the EDMX from a DbContext created using Database First or Model First is not supported. EDMX can only be obtained from a Code First DbContext created without using an existing DbCompiledModel.

    Please help!

  • User profile image

    Find the problem:

    - First should install Entity Framework 6.1.0 Tools for Visual Studio 2012 & 2013

    - Then update to EF6.1

    - Follow video.


  • User profile image

    When defining models with Entity Framework's Code First and a DbContext class, I find the "View Model" feature of the Entity Framework Power Tools Beta 3 completely indispensable. Without it, I only *think* I know what I've told EF my model should be but I don't really know how Code First will interpret the information I've provided.

    Any plans to get this feature back ? PLEASE!!

  • User profile image
    Thank you very much for this very instructive video series on EF. With it, I learned from scratch database with SQL Server. Let me have a few comments when I transferred it to my environment. I develop with VS 2019 v. 16.0.0 preview 2.2 and SQL Server Express 2017 on Windows Server 2016 virtual machine. There is IIS10 running with Default Web Site as a production site and Alpha as development site. I have used access to database file in destination database, not by SQL server. There happened several issues:
    1. in publish process the App_Data folder was not created, it was empty in solution, however both users´ database and equivalent of AdventureWorks2012 were connected, what could be seen in Server Explorer of CS2019.
    2. If your destination database is a file and not a database in SQL server, the destination file must be specified with full path AND the directory of the database file must exist. It seems that all the database construction is not capable of creating of the directory.
    3. Users´ database is created on the fly upon registering of the first user in the development site. However you HAVE to specify all connection string to non-existing database file, with the full path to existing directory. Therefore in Publishing, check "Exclude App_Data directory", if you delete all of the existing files at destination, otherwise the App_Data will be deleted and nowhere to create database files.
    4. When you do Initial migration and your remote database does not exist, avoid selecting _MigrationsHistory table for migrations! In new SQL server versions it seems to be created when the database is created, so you can write to it the migrations, but do not create it.
    5. In my environment, somehow after publishing the new website was not run. I had to do it manually. Remember I had to run the equivalent of http://Alpha, not an Azure website. For whatever reason https://Alpha was working, but users´ database was not being created. When I used http://Alpha, there was no problem anymore and both databases were created in manually created App_Data directory.

Add Your 2 Cents