Entity Framework 4.3 doesn't create database

前端 未结 2 1256
孤街浪徒
孤街浪徒 2020-12-18 04:44

I created new project and added the newest entity framework to it (version 4.3). I created classes and the context as in previous EF versions. However, during the very first

相关标签:
2条回答
  • 2020-12-18 05:22

    Could you try removing your constructor to make EF use it's default connection string.

    public Context() : base("MyConnection")
    {
    }
    

    Failing that, could you try updating your database from the Package Manager Console to see if you get any further information.

    Update-Database -Verbose
    

    Possibly unrelated in your case, but I get the same error when using MvcMiniProfiler 1.9. If you are using it too, make sure EF profiling is turned off by commenting out the line:

    //MiniProfilerEF.Initialize();
    

    Within the MiniProfiler App_Start.


    For others experiencing a similar issue, I have found that reenabling migrations from the Package Manager Console can help in certain cases. Make sure you have a copy of your Migration configuration before doing this.

    Enable-Migrations -Force
    
    0 讨论(0)
  • 2020-12-18 05:42

    ...and just to add one more possible answer for all those facing similar problem
    (note: this is an open-ended story seems, as there're obviously some bugs still with the migration part)... This link came closest to what I needed
    Error when running Update-Database with EF 4.3 so, you need to do 3 things (in that order - and I'm referring to an existing project):
    (all is in PM console)

    • Make sure that 'default project' in PM Console is set to your desired project (i.e. for larger solutions) - that doesn't necessarily match your startup project! (and closely watch the comments/response in PM as to whether the actions were made on the project you want)
    • (1) Enable-Migrations -force
    • (2) Add-Migration Initial
    • (3) Update-Database -Verbose

    ...if you still get an exception in PM console

    • (4) then you might need to 'move' your project into the root

    it sounds silly I know, but that was the main problem on my side - I had a bunch of solution folders and any of the above would fail on projects within solution folders. However, once I moved the project to the root, everything worked fine (no more exceptions, with or w/o first-chance exceptions for CLR turned on or off)...
    hope this helps somebody

    EDIT: if your data model project (EF CF) is a library - then set that project as a 'default project' in PM console - and run all those things above on that project directly (and have migration configuration etc. created in the lib itself). Otherwise it'd fail (and the same no MigrationHistory exception also appears when your model is a lib - and no migration defined for it, within it - and you have migration defined on the 'main project').

    EDIT: you'd need to move both the lib (EF model) and the 'startup' project (calling it) into the root.

    0 讨论(0)
提交回复
热议问题