-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Primary Keys mangled on generic DbSets models after second migration #3545
Comments
Hmm.. I am not able to reproduce this on the nightly builds. @TsengSR, would you mind trying again to see if it's fixed? |
Yes, it's still there. Using EntityFramework.MicrosoftSqlServer 7.0.0-rc2-16332 and EntityFramework.Commands 7.0.0-rc2-16332 and Microsoft.AspNet.Identity.EntityFramework 3.0.0-rc2-16069. It happens only on Models containing generics, even if nothing on the model has been changed. Just calling "dnx ef migrations add Init" twice on a fresh migration and the above models. I did a few further tests and the issue doesn't appear when using the Standard Identity models (which use string as TKey). In my case above I use Guid. I used this models in my project
And in the Startup.cs the following configurations for Identity & EntityFramework:
Removing the Guid everywhere and using |
Thanks, I'll keep digging. I took ASP.NET Identity out of the picture when attempting to repro, but I'll throw it into the mix to see if it changes anything. |
It looks like the issue is actually generic foreign keys closed over non-built-in types. The following model reproduces the issue. I'll start working on a fix. class AuthUser
{
public Guid Id { get; set; }
[ForeignKey("UserId")]
public ICollection<IdentityUserRole<Guid>> Roles { get; }
}
class IdentityUserRole<TKey>
{
public int Id { get; set; }
public TKey UserId { get; set; }
}
class AuthContext : DbContext
{
public DbSet<AuthUser> Users { get; set; }
} |
Good bug. This affected table, primary key, foreign key, unique constraint, and index names on a generic entity type. |
This is happening for me too. |
Is the bugfix included in the latest v7.0.0-rc2-16432 nightlies? |
@TsengSR No, I sent out a PR, but we discussed and decided to take a slightly different approach. It should be fixed sometime next week. |
Is there a workaround available for this in RC1, since RC2 is still some time away? |
@JesperTreetop Explicitly configuring the entities by calling |
The migration file (i.e. 20151024123838_Init.cs) gets mangled primary keys on second migration.
I am using AspNet Identity in my project and after the initial migration the 2nd (and following) migrations will mangle the primary keys, basically making it impossible to migrate further and having to wipe of the database after each change in the structure.
For example:
After setting up the initial project, run a migration
dnx ef migrations add Init
The files genreated are generated correctly. Without further change, add a second migration
dnx ef migrations add Init2
The Init2 file (i.e.20151024123846_Init2.cs) has mangled primary keys:
First imgration (20151024123838_Init.cs):
Second, mangeld migration (20151024123846_Init2.cs):
The
dnx ef database update
will now of course fail.As you can see "FK_IdentityRoleClaim_AuthRole_RoleId" got mangled into "FK_Guid>_AuthRole_RoleId" and the "IdentityRoleClaim<" was removed.
It's a big game breaker, as migrations stop working when generic models are used.
The text was updated successfully, but these errors were encountered: