简体   繁体   中英

Migration does not create the database

I run normal migration and it normally creates migration, only it does not create the database. On another computer he created usually using the same settings, only on the one that is not giving. only the file in the migration folder. I've tried everything practically, if anyone knows how to answer I'll be grateful. asp.net core MVC and visual studio.

Context class:

  public class ProjectContext : DbContext
  {
  public ProjectContext(DbContextOptions<ProjectContext> options)
  : base(options)

{ }

   (appsettings.json)
   "ConnectionStrings": {
  "ProjetoTIConnection": "Server=localhost;Database=projetoti;Trusted_Connection=true"
}

(Startup.cs)

public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<ProjectContext>(options => 
options.UseSqlServer(Configuration.GetConnectionString("ProjetoTIConnection")));

Please check the name of the server where you want to create database.

In visual studio, you can open View > SQL Server Object Explorer in tool menu, then expend SQL Server node.

Here is my SQL Server Object Explorer structure:

在此处输入图片说明

So, the ConnectionStrings in appsettings.json should be :

  "ConnectionStrings": {
    "ProjetoTIConnection": "Server=(localdb)\\mssqllocaldb;Database=projetoti;Trusted_Connection=true"
   } 

Then, after excuting the command of add-migration and update-database , the database named
projetoti will be created in the server which name is (localdb)\\\\mssqllocaldb .

So, please check your server name and ensure that the server name in the connection string is consistent with it.

You should also check the version of node you are using.

migration:run stopped working when installed node v16.

But after I switched back to v18 it stated working fine.

I guess there is an issue with older node version support.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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