Entity Framework Core migrations with identity db contextHow to delete and recreate from scratch an existing EF Code First databaseEntity Framework vs LINQ to SQLHow can I change the table names when using ASP.NET Identity?Entity Framework Seeding with Identity (Microsoft.Owin.Security) userSetting Up ASP.NET Identity Core in an empty ASP.NET Core Web ApplicationCustom Identity EntityFrameworkCoreInclude operator could not be bound in Entity Framework Core with Identity DBUndo HasIndex in OnModelCreatingMigrations is not detecting added property to ApplicationRole : IdentityRoleDot Net Core Identity User reference as Foreign in ApplicationDBContextIssue on add-migration in this current bridging class (many-to-many)

Power LED from 3.3V Power Pin without Resistor

How to implement float hashing with approximate equality

What happened to Rhaegal?

When and why did journal article titles become descriptive, rather than creatively allusive?

Feels like I am getting dragged into office politics

Pressure to defend the relevance of one's area of mathematics

How do you center multiple equations that have multiple steps?

Is it cheaper to drop cargo than to land it?

LT Spice Voltage Output

How to reply this mail from potential PhD professor?

Password expiration with Password manager

If Earth is tilted, why is Polaris always above the same spot?

Why do money exchangers give different rates to different bills

Unidentified items in bicycle tube repair kit

Is this homebrew race based on the Draco Volans lizard species balanced?

Survey Confirmation - Emphasize the question or the answer?

Why is the SNP putting so much emphasis on currency plans?

How did Arya manage to disguise herself?

How did Captain America use this power?

Was the ancestor of SCSI, the SASI protocol, nothing more than a draft?

Is there a QGIS plugin that reclassify raster symbology based on current extent?

Would "lab meat" be able to feed a much larger global population

How long can a 35mm film be used/stored before it starts to lose its quality after expiry?

Can commander tax be proliferated?



Entity Framework Core migrations with identity db context


How to delete and recreate from scratch an existing EF Code First databaseEntity Framework vs LINQ to SQLHow can I change the table names when using ASP.NET Identity?Entity Framework Seeding with Identity (Microsoft.Owin.Security) userSetting Up ASP.NET Identity Core in an empty ASP.NET Core Web ApplicationCustom Identity EntityFrameworkCoreInclude operator could not be bound in Entity Framework Core with Identity DBUndo HasIndex in OnModelCreatingMigrations is not detecting added property to ApplicationRole : IdentityRoleDot Net Core Identity User reference as Foreign in ApplicationDBContextIssue on add-migration in this current bridging class (many-to-many)






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I've setup a .net core api app to host JWT token authentication using an asp identity database. That part works great. My problem is when I go to add custom classes, every migration I perform is trying to create the AspNet* tables again even though they exist. The migration is aware of my custom class (Test) and wants to create it, but the script it's trying to run dies on the AspNetRoles table (already exists error).



I create a new migration:



Add-Migration NewMigration


Then update:



Update-Database


Here is my ApplicationDBContext.cs:



public class ApplicationDBContext : IdentityDbContext<ApplicationUser>

public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)



// This is my custom class
public DbSet<Test> Test get; set;

protected override void OnModelCreating(ModelBuilder builder)

base.OnModelCreating(builder);




I'm at a loss. I just need to do migrations and have EF Core ignore the AspNet identity tables.



Edit: Here is ApplicationUser.cs



public class ApplicationUser : IdentityUser




Migrations folder:



enter image description here










share|improve this question
























  • Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

    – David Liang
    Mar 22 at 19:58











  • Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

    – AS2012
    Mar 22 at 20:08











  • I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

    – David Liang
    Mar 22 at 21:47






  • 1





    Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

    – Christian Gollhardt
    Mar 23 at 1:20












  • I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

    – AS2012
    Mar 25 at 14:08


















0















I've setup a .net core api app to host JWT token authentication using an asp identity database. That part works great. My problem is when I go to add custom classes, every migration I perform is trying to create the AspNet* tables again even though they exist. The migration is aware of my custom class (Test) and wants to create it, but the script it's trying to run dies on the AspNetRoles table (already exists error).



I create a new migration:



Add-Migration NewMigration


Then update:



Update-Database


Here is my ApplicationDBContext.cs:



public class ApplicationDBContext : IdentityDbContext<ApplicationUser>

public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)



// This is my custom class
public DbSet<Test> Test get; set;

protected override void OnModelCreating(ModelBuilder builder)

base.OnModelCreating(builder);




I'm at a loss. I just need to do migrations and have EF Core ignore the AspNet identity tables.



Edit: Here is ApplicationUser.cs



public class ApplicationUser : IdentityUser




Migrations folder:



enter image description here










share|improve this question
























  • Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

    – David Liang
    Mar 22 at 19:58











  • Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

    – AS2012
    Mar 22 at 20:08











  • I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

    – David Liang
    Mar 22 at 21:47






  • 1





    Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

    – Christian Gollhardt
    Mar 23 at 1:20












  • I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

    – AS2012
    Mar 25 at 14:08














0












0








0








I've setup a .net core api app to host JWT token authentication using an asp identity database. That part works great. My problem is when I go to add custom classes, every migration I perform is trying to create the AspNet* tables again even though they exist. The migration is aware of my custom class (Test) and wants to create it, but the script it's trying to run dies on the AspNetRoles table (already exists error).



I create a new migration:



Add-Migration NewMigration


Then update:



Update-Database


Here is my ApplicationDBContext.cs:



public class ApplicationDBContext : IdentityDbContext<ApplicationUser>

public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)



// This is my custom class
public DbSet<Test> Test get; set;

protected override void OnModelCreating(ModelBuilder builder)

base.OnModelCreating(builder);




I'm at a loss. I just need to do migrations and have EF Core ignore the AspNet identity tables.



Edit: Here is ApplicationUser.cs



public class ApplicationUser : IdentityUser




Migrations folder:



enter image description here










share|improve this question
















I've setup a .net core api app to host JWT token authentication using an asp identity database. That part works great. My problem is when I go to add custom classes, every migration I perform is trying to create the AspNet* tables again even though they exist. The migration is aware of my custom class (Test) and wants to create it, but the script it's trying to run dies on the AspNetRoles table (already exists error).



I create a new migration:



Add-Migration NewMigration


Then update:



Update-Database


Here is my ApplicationDBContext.cs:



public class ApplicationDBContext : IdentityDbContext<ApplicationUser>

public ApplicationDBContext(DbContextOptions<ApplicationDBContext> options) : base(options)



// This is my custom class
public DbSet<Test> Test get; set;

protected override void OnModelCreating(ModelBuilder builder)

base.OnModelCreating(builder);




I'm at a loss. I just need to do migrations and have EF Core ignore the AspNet identity tables.



Edit: Here is ApplicationUser.cs



public class ApplicationUser : IdentityUser




Migrations folder:



enter image description here







entity-framework .net-core entity-framework-core asp.net-identity asp.net-core-webapi






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 21:32









marc_s

587k13011281274




587k13011281274










asked Mar 22 at 19:48









AS2012AS2012

2111028




2111028












  • Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

    – David Liang
    Mar 22 at 19:58











  • Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

    – AS2012
    Mar 22 at 20:08











  • I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

    – David Liang
    Mar 22 at 21:47






  • 1





    Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

    – Christian Gollhardt
    Mar 23 at 1:20












  • I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

    – AS2012
    Mar 25 at 14:08


















  • Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

    – David Liang
    Mar 22 at 19:58











  • Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

    – AS2012
    Mar 22 at 20:08











  • I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

    – David Liang
    Mar 22 at 21:47






  • 1





    Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

    – Christian Gollhardt
    Mar 23 at 1:20












  • I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

    – AS2012
    Mar 25 at 14:08

















Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

– David Liang
Mar 22 at 19:58





Can you show one of your classes inherited from those 7 built-in ASP.NET Core Identity entities, i.e. ApplicationUser? Also a screenshot of the migration folder and how you add this ApplicationDbContext to your main web project would be helpful.

– David Liang
Mar 22 at 19:58













Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

– AS2012
Mar 22 at 20:08





Edited to add ApplicationUser class (empty) and screenshot of the migration folder. I manually added the ApplicationDbContext to the Api project.

– AS2012
Mar 22 at 20:08













I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

– David Liang
Mar 22 at 21:47





I manually created DbContext too. That should have no problem. Did you use services.AddIdentity<ApplicaitonUser, IdentityRole>(...) to register the identity service at Startup.cs?

– David Liang
Mar 22 at 21:47




1




1





Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

– Christian Gollhardt
Mar 23 at 1:20






Did you by chance manipulated or deleted your __MigrationHistory table? Try start clean. I see no problems with you current code.

– Christian Gollhardt
Mar 23 at 1:20














I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

– AS2012
Mar 25 at 14:08






I deleted the db and started clean as Christian had suggested and everything is working as expected now. Something must have gotten out of sync somewhere. Luckily the database didn't have any data in it yet. I will vote this as the answer if you post it.

– AS2012
Mar 25 at 14:08













0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306860%2fentity-framework-core-migrations-with-identity-db-context%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306860%2fentity-framework-core-migrations-with-identity-db-context%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript