Consider Migrations
If applicable, you need to consider building a migration, which will allow you to generate (and potentially execute) the necessary scripts to create the appropriate tables or changes within your database.
By default, you should have some type of ApplicationDbContext
class that looks like the following which will be used to define your "security-related" database:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", false)
{
}
// Other code omitted for brevity
}
You'll then just need to run the Enable-Migrations command in Package Manager Console:
Enable-Migrations
This should generate a Migrations folder within your application that contains various configuration files that control how migrations are preformed as well as an InitialCreate
migration. This may only be present if you previously had some Code-First related code within your application, if not, don't worry about it. You can then try running the Update-Database command, which should execute any migrations (including an initial one) against your database:
Update-Database
Once your database has been updated, you can continue to make changes to your model and simply create and execute new migrations through the Add-Migration command and the previous Update-Database command:
Add-Migration "AddedAnotherPropertyToFoo"
Update-Database
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…