简体   繁体   English

使用已经准备好的迁移ASP.NET MVC创建数据库

[英]Creating database using already prepared migrations ASP.NET MVC

I have a ASP.NET MVC 5 project from GitHub, but there is nothing in App_Data . 我有一个来自GitHub的ASP.NET MVC 5项目,但App_Data没有任何内容。 I have all models, migrations etc... I'm sure that everything works. 我拥有所有模型,移植等...我确定一切正常。 I'd like to create database to use this project. 我想创建数据库以使用此项目。 How can I create it? 如何创建它?

There is a PowerShell command that comes with Entity Framework Code First which updates the database based on the migrations in the project: Entity Framework Code First附带有一个PowerShell命令 ,该命令根据项目中的迁移更新数据库:

Update-Database will apply any pending migrations to the database Update-Database将所有未决的迁移应用到数据库

You can run this easily from within Visual Studio using the Package Manager Console ( Tools –> Library Package Manager –> Package Manager Console ). 您可以使用包管理器控制台工具 –> 库包管理器 –> 包管理器控制台 )在Visual Studio中轻松运行此程序 Make sure to select the project that contains the DbContext class as Startup Project in Solution Explorer as well as Default Project in Package Manager Console, before running the Update-Database command. 在运行Update-Database命令之前,请确保选择包含DbContext类的项目作为Solution Explorer中的Startup Project以及Package Manager Console中的Default Project。 Also ensure you have defined a connection string for a local database that the command will update. 另外,请确保已为命令将更新的本地数据库定义了连接字符串。

For more details follow the instructions in documentation . 有关更多详细信息,请遵循文档中的说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM