0

I already created a Asp.net core web api project and have created a database using identity with migration. Now I need to know, that can I add new table to the database and how can i do that? I'm new to this field.

I also have tried Add-Migration but giving me error. I have no idea about this.

The error message is:

An error occurred while accessing the IWebHost on class 'Program'. Continuing without the application service provider. Error: AddEntityFrameworkStores can only be called with a user that derives from IdentityUser. More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.

halfer
  • 19,824
  • 17
  • 99
  • 186
Ranto Berk
  • 351
  • 1
  • 3
  • 13
  • You've got 2 contexts so you need to parameterize your commands. See [here](https://stackoverflow.com/questions/21537558/multiple-db-contexts-in-the-same-db-and-application-in-ef-6-and-code-first-migra). – Steve Greene Jun 19 '19 at 20:30

1 Answers1

0

Create your model and add in DB context.

public DbSet<UserAttachment> UserAttachment {get; set;}

After that

add-migration 

And then

update-database
sudesh regmi
  • 536
  • 4
  • 12
  • Tried this. But giving me error....{An error occurred while accessing the IWebHost on class 'Program'. Continuing without the application service provider. Error: AddEntityFrameworkStores can only be called with a user that derives from IdentityUser. More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.} – Ranto Berk Jun 18 '19 at 05:35
  • error is saying the more than one dbcontext found please make sure to use only one. – sudesh regmi Jun 18 '19 at 05:38
  • ok. I tried to add two DBContext. now i deleted those files and lines added. Is there any way to add new table with help of old migration? – Ranto Berk Jun 18 '19 at 05:40
  • delete you migration folder and try to make new db context file and add migration again – sudesh regmi Jun 18 '19 at 05:44
  • delete the folder with cmd? or by right click - delete? – Ranto Berk Jun 18 '19 at 05:49
  • Hey, Can you help me? I need to create two tables, but I have already created one table with migration. Is there anyway we can add new table to same database through that old migration – Ranto Berk Jun 18 '19 at 06:17
  • yes add another dbset in dbcontext and add-migration after that update-databse – sudesh regmi Jun 18 '19 at 06:20
  • when i done that only i get that error that i mentioned above – Ranto Berk Jun 18 '19 at 06:21
  • please provide screenshot or code in regmi.sudesh098@gmail.com – sudesh regmi Jun 18 '19 at 06:29
  • have mailed you. please check it – Ranto Berk Jun 18 '19 at 06:38