Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EF 7] Upgrading to beta 5 breaks migrations #35

Open
natemcmaster opened this issue Jun 26, 2015 · 16 comments
Open

[EF 7] Upgrading to beta 5 breaks migrations #35

natemcmaster opened this issue Jun 26, 2015 · 16 comments

Comments

@natemcmaster
Copy link
Contributor

Entity Framework 7 projects that use migrations may encounter breaking changes when upgrading from beta4 to beta5.

Problems

ModelSnapshot

'ApplicationDbContextModelSnapsnot.Model': no suitable method found to override

This error occurs when upgrading an application that used the beta 4 template and EntityFramework is upgraded to beta5.

Fix

To fix this error, delete the file Migrations/ApplicationDbContextModelSnapshot.cs. Regenerate the model snapshot by adding a new migration by running this command from the command prompt in the root folder of the MVC project. dnx . ef migration add Empty.

CreateIdentitySchema migration

A few errors make occur until Migrations/000000_CreateIdentitySchema.cs is changed to match the new Migration API.

'CreateIdentitySchema.Target': no suitable method found to override

The type or namespace name 'BasicModelBuilder' could not be found

Fix

Modify Migrations/000000_CreateIdentitySchema.cs to match the new migrations API.

Convert the Target property in the CreateIdentitySchema class to a method

public override void BuildTargetModel(ModelBuilder builder) 

Remove the instantiation of new BasicModelBuilder() and use instead the ModelBuilder instance passed into this method.

The foreign key API has also changed. Fix the broken foreign key configuration using this pattern:

 builder.Entity("Microsoft.AspNet.Identity.EntityFramework.IdentityRoleClaim<string>", b =>
                {
                    b.Reference("Microsoft.AspNet.Identity.EntityFramework.IdentityRole")
                        .InverseCollection()
                        .ForeignKey("RoleId");
                });
@natemcmaster natemcmaster changed the title [EF 7] Upgrading to beta 5 requires regenerating ModelSnapshot [EF 7] Upgrading to beta 5 breaks migrations Jun 26, 2015
@jsinh
Copy link

jsinh commented Jun 26, 2015

Updated: Typo in public override void BuildeTargetModel(ModelBuilder builder) method name

@dmccaffery
Copy link

dmccaffery commented Jun 26, 2015 via email

@natemcmaster
Copy link
Contributor Author

@jsinh good catch. Fixed.

@Eilon Eilon added this to the 1.0.0-beta5 milestone Jun 27, 2015
@witek1902
Copy link

After this change I have problem with ForeignKey.
In beta4 we had:

public virtual ForeignKeyBuilder ForeignKey([NotNullAttribute]string referencedEntityTypeName, [NotNullAttribute]params string[] propertyNames);

And now we have:

public virtual ForeignKey AddForeignKey([NotNullAttribute]Property property, [NotNullAttribute]Key principalKey, [CanBeNullAttribute]EntityType principalEntityType = null);

How can I add new foreign key?

@natemcmaster
Copy link
Contributor Author

@witek1902 Yes, the foreign key API also changed. I've upgraded the original comment above to include a note on fixing these: ⏫

@mbharodia
Copy link

When I run command to regenerate migration I get the following error

image

Any idea to fix it ?

I am running this command at a location where project.json file exists as shown below.

image

I have added a new issue on dnx. The following is a link
aspnet/dnx#2256

@natemcmaster
Copy link
Contributor Author

@mbharodia from initial inspection, no I am not sure how to fix this. Please create a question on Stack Overflow or a Github issue on dnx and update your comment above with a link.

@mail2gbaskar
Copy link

Fixed. Issue got Resolved after Installing Microsoft.AspNet.SignalR.Server 3.0.0-beta4

@mbharodia
Copy link

Oh... good to know. Thanks a lot for the heads up.

@developer1998
Copy link

I am using

    "version": "1.0.0-beta7-12290",
    "runtime": "clr",
    "architecture": "x64"

When I run the command dnx . ef migration add Empty
I get:

System.ArgumentNullException: Value cannot be null.
Parameter name: appEnv
   at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
   at Microsoft.Data.Entity.Commands.Program..ctor(IServiceProvider serviceProvider, IApplicationEnvironment appEnv, ILibraryManager libraryManager, IRuntimeEnvironment runtimeEnv, IApplicationShutdown applicationShutdown)

my ef command is specified as so in project.json

"ef": "EntityFramework7.Commands"

How can I resolve this, thanks.

@NoralK
Copy link

NoralK commented Aug 2, 2015

Commands have changed slightly:

E:\Projects\HelloMvc>dnx . ef migrations add empty --context PersonDBContext
Using context 'PersonDBContext'.
Writing migration to 'E:\Projects\HelloMvc\Migrations\20150802041042_empty.cs'.
Writing model snapshot to 'E:\Projects\HelloMvc\Migrations\PersonDBContextModelSnapshot.cs'.
Done. To undo this action, use 'ef migrations remove'

Hope this helps you.

@developer1998
Copy link

You know what it is, my

dnx . ef

is not working at all, it is broken
when I run it I get

System.ArgumentNullException: Value cannot be null.
Parameter name: appEnv
   at Microsoft.Data.Entity.Utilities.Check.NotNull[T](T value, String parameterName)
   at Microsoft.Data.Entity.Commands.Program..ctor(IServiceProvider serviceProvider, IApplicationEnvironment appEnv, ILibraryManager libraryManager, IRuntimeEnvironment runtimeEnv, IApplicationShutdown applicationShutdown)

Am I missing a dependency, here is my project.json list

  "dependencies": {
    "Microsoft.AspNet.Diagnostics": "1.0.0-*",
    "Microsoft.AspNet.Diagnostics.Entity": "7.0.0-*",
    "Microsoft.AspNet.Mvc": "6.0.0-*",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-*",
    "Microsoft.AspNet.Server.IIS": "1.0.0-*",
    "Microsoft.AspNet.Server.WebListener": "1.0.0-*",
    "Microsoft.AspNet.Identity.EntityFramework": "3.0.0-*",
    "Microsoft.Framework.Configuration": "1.0.0-*",
    "Microsoft.Framework.Configuration.Json": "1.0.0-*",
    "EntityFramework7.SqlServer": "7.0.0-*",
    "EntityFramework7.Core": "7.0.0-*",
    "EntityFramework7.Commands": "7.0.0-*",
    "Microsoft.Framework.Logging": "1.0.0-*",
    "Microsoft.Framework.Logging.Console": "1.0.0-*",
    "Microsoft.AspNet.StaticFiles": "1.0.0-*"
  },

Thank you for your help.

@developer1998
Copy link

I got ef working, EntityFramework7.Commands got renamed back to EntityFramework.Commands. So this fixed it.
Now I have a small problem with Startup.cs:

Unable to resolve service for type 'Microsoft.Framework.Runtime.IApplicationEnvironment'

@ph1ll
Copy link

ph1ll commented Aug 2, 2015

@developer1998 are you using beta7? There has been a rename as per #51 Microsoft.Framework.Runtime is now Microsoft.Dnx.Runtime

@developer1998
Copy link

@ph1ll that did it, thank you

dnx . ef migrations add CreateIdentitySchema

Almost there... Now I am getting en error within the schema itself. Looks like I am missing a reference

The name 'SqlServerIdentityStrategy' does not exist in the current context

@developer1998
Copy link

Got it, referencing using Microsoft.Data.Entity.SqlServer.Metadata; solved it. Thank you so much for all the help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants