当开发环境设置为使用sqlite时,使用SQL Server进行迁移

时间:2018-04-01 13:37:13

标签: c# .net-core

我在使用.NET Core 2.0的MAC上

我的program.cs文件设置了我的机器上开发的环境集

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                //.UseStartup<Startup>()
                   .UseStartup("MoviesLibfrary")
                .Build();

我有一个名为StartupDevelopment的新课程:

public class StartupDevelopment 
{
        public StartupDevelopment(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.AddMvc();

            services.AddDbContext<MvcTriviaContext>(options =>
                                                    options.UseSqlite(Configuration.GetConnectionString("MvcTriviaContext")));
        }
}

调试应用程序确实使用StartupDevelopment类。

使用dotnet ef migrations add InitialCreatedotnet ef database update正在尝试使用SQL Server。

运行数据库升级时遇到的错误

  

建立与SQL Server的连接时发生与网络相关或特定于实例的错误。服务器未找到或无法访问。验证实例名称是否正确,以及SQL Server是否配置为允许远程连接。 (提供者:TCP提供者,错误:25 - 连接字符串无效)

appsettings.Development.json中的连接字符串:

"ConnectionStrings": {
    "MvcTriviaContext": "Data Source=Data\\databasename.db"
  }

如何将dotnet ef用于sqlite,因为我的开发环境被指定为使用sqlite?

0 个答案:

没有答案