-
Notifications
You must be signed in to change notification settings - Fork 847
No foreign key constraint on custom AspNetUserTokens #1023
Description
Functional impact
No functionality from foreign key in database in table AspNetUserTokens and AspNetUsers.
Minimal repro steps
- Create new Code-First model with Identity
- Create custom models with custom key, I used
System.Guid - Create a migration, and deploy it to SQL Server
Expected result
The table AspNetUserTokens should have a foreign key constraint to table AspNetUsers.
Actual result
The table AspnetUserTokens is not related at all in database to table AspNetUsers.
Further technical details
The database is implemented in class project file, which is referenced by the ASP.NET project. All migrations were made through the ASP.NET project.

Screenshot from SQL Server database diagram
The tables were renamed through OnModelCreating override. Derived classes have no additional code at all, apart from User, which has several fields and navigation properties added. This should not impact the issue at all, however.
I'm using Windows 10 x64 with SQL Server Express 2014. IDE is VS 2015 Enterprise Update 3.
Project.json file for database class project:
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.AspNetCore.Identity": "1.1.0-preview2-22681",
"Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.1.0-preview2-22681",
"Microsoft.EntityFrameworkCore": "1.1.0-preview2-22681",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview2-22681",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-22681",
"NETStandard.Library": "1.6.1"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
Project.json file for ASP.NET project:
{
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Razor.Tools": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.1.0-preview2-22681",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
"CoreTests.Database": "1.0.0-*",
"Microsoft.EntityFrameworkCore.SqlServer": "1.1.0-preview2-22681",
"Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-22681",
"Microsoft.EntityFrameworkCore.Design": "1.1.0-preview2-22681",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0-preview2-22675"
},
"tools": {
"BundlerMinifier.Core": "2.0.238",
"Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"runtimeOptions": {
"configProperties": {
"System.GC.Server": true
}
},
"publishOptions": {
"include": [
"wwwroot",
"Views",
"Areas/**/Views",
"appsettings.json",
"web.config"
]
},
"scripts": {
"prepublish": [ "bower install", "dotnet bundle" ],
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}