繁体   English   中英

visual studio 的 package 管理控制台中的添加迁移未在我的本地 sql 服务器中创建数据库

[英]Add-Migration in package management console of visual studio not creating database in my local sql server

我是新的 .net 核心 angular 和EntityFrameworkCore 我正在使用此链接.Net Angular Core上使用视频教程。 在模块 6,服务和后端 - 第 7 章,使用 EF Core 创建数据库,通过在 appsettings.json 和 startup.cs 中配置创建数据库 MoviesAPI。 我按照视频中老师的步骤在本地 SQL Server Express 中创建了一个数据库 MoviesAPI 我的本地 SQL Server 2012 .

首先,我尝试在 appsettings.json 中使用教师的 DefaultConnection 配置,但在使用我的命令 Add-Migration Initial 在我的 Visual Studio package 管理器控制台中没有在我的 sql 服务器中创建任何数据库 MoviesAPI。

    "ConnectionStrings": {
    "DefaultConnection": "Data Source=.;Initial Catalog=MoviesAPI;Integrated Security=True;"

  }

然后我尝试在下面使用它,但它仍然没有在我的计算机上的 sql 服务器中创建数据库。

"DefaultConnection": "Data Source=LAPTOP-5QTMTD1A\\SQLEXPRESS;Initial Catalog=MoviesAPI;Integrated;Security=True"

在这两种情况下,我都在我的 package 管理器控制台中成功构建。

构建开始...构建成功。 要撤消此操作,请使用 Remove-Migration。

我的 Startup.cs

            using Microsoft.AspNetCore.Authentication.JwtBearer;
        using Microsoft.AspNetCore.Builder;
        using Microsoft.AspNetCore.Hosting;
        using Microsoft.Extensions.Configuration;
        using Microsoft.Extensions.DependencyInjection;
        using Microsoft.Extensions.Hosting;
        using Microsoft.Extensions.Logging;
        using Microsoft.OpenApi.Models;
        using MoviesApi.Filters;

        using Microsoft.EntityFrameworkCore;

        namespace MoviesApi
        {
            public class Startup
            {
                public Startup(IConfiguration configuration)
                {
                    Configuration = configuration;
                }

                public IConfiguration Configuration { get; }

                // This method gets called by the runtime. Use this method to add services to the container.
                public void ConfigureServices(IServiceCollection services)
                {
                    services.AddDbContext<ApplicationDBContext>(options=> {
                        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
                    });
                    services.AddCors(options => {
                        options.AddDefaultPolicy(builder => {
                            var frontendURL = Configuration.GetValue<string>("frontend_url");
                            builder.WithOrigins(frontendURL).AllowAnyMethod().AllowAnyHeader();
                        });
                    });
                    services.AddControllers(options=> {
                        options.Filters.Add(typeof(MoviesExceptionFilter));
                    });
                    //E nsures all actions and controllers have simple caching mechanism in the webapi
                    services.AddResponseCaching();
                    services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer();
       
                    services.AddSwaggerGen(c =>
                    {
                        c.SwaggerDoc("v1", new OpenApiInfo { Title = "MoviesApi", Version = "v1" });
                    });
                }

                // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
                public void Configure(IApplicationBuilder app, IWebHostEnvironment env,ILogger<Startup> logger)
                {

      
                    if (env.IsDevelopment())
                    {
                        app.UseDeveloperExceptionPage();
                        app.UseSwagger();
                        app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "MoviesApi v1"));
                    }

                    app.UseHttpsRedirection();

                    app.UseRouting();
                    app.UseCors();
                    //Intercept http request returned from the cache
                    //app.UseResponseCaching();
                    app.UseAuthentication();
                    app.UseAuthorization();

                    app.UseEndpoints(endpoints =>
                    {
                        endpoints.MapControllers();
                    });
                }
            }
        }

在阅读了关于stackoverflow上类似帖子的一些评论后,我在我的 package 管理器控制台中运行了命令,它最终给了我这些警告,但我不知道这些警告是否与无法通过创建数据库有关添加迁移初始命令。

更新数据库 - 详细

警告

安全警告:协商的 TLS 1.0 是一个不安全的协议,仅支持向后兼容。 推荐的协议版本是 TLS 1.2 及更高版本。 安全警告:协商的 TLS 1.0 是一个不安全的协议,仅支持向后兼容。 推荐的协议版本是 TLS 1.2 及更高版本。 安全警告:协商的 TLS 1.0 是一个不安全的协议,仅支持向后兼容。 推荐的协议版本是 TLS 1.2 及更高版本。

我有一个项目也有 TLS 1.0 的这个问题。 它在我学校的电脑上正常工作,但在我的电脑上却不能(浏览器不接受该协议)。 关于您创建数据库的问题,您是否尝试过使用 Microsoft SQL Server Management Studio 18? 我的项目使用它,我的字符串连接是这样的"ConnectionStrings": { "DBcadastro_clientes": "Server=PCNAMEHERE\\SQLEXPRESS;Database=DBcadastro_clientes;User Id=sa;Password=sa;"}, "AllowedHosts": "*" }

暂无
暂无

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

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