简体   繁体   English

如何从Linux上的asp.net核心应用程序迁移表

[英]How to migrate my tables from my asp.net core app on linux

I have made an asp.net core app that runs perfectly in my windows machine. 我制作了一个在Windows机器中完美运行的asp.net核心应用程序。 I need to deploy this app on a Linux machine. 我需要在Linux机器上部署此应用程序。 My problem comes when migrating my tables into MySQL server on the Linux machine. 将表迁移到Linux计算机上的MySQL服务器时,出现了我的问题。 I have the Linux machine for production purposes and I need MySQL server for users handling. 我拥有用于​​生产目的的Linux机器,并且需要MySQL服务器来处理用户。 I have created a database but when I run the command dotnet ef database update to migrate my tables into this database I see the following error: 我已经创建了一个数据库,但是当我运行命令dotnet ef database update将表迁移到该数据库时,我看到以下错误:

在此处输入图片说明

My connection string used for the connection to my database is the following : 我用于连接数据库的连接字符串如下:

  "ConnectionStrings": {
    "DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=ElectransUsers;Trusted_Connection=True;MultipleActiveResultSets=true"
  },

If I change the connection string writing localhost instead of localdb I see the following error: 如果更改写入本地主机而不是localdb的连接字符串,则会看到以下错误: 在此处输入图片说明

If I remove mssqllocaldb I see the following error: 如果删除mssqllocaldb,则会看到以下错误:

在此处输入图片说明 And my Configure method in the Startup.cs script is the following: 我在Startup.cs脚本中的Configure方法如下:

    public void ConfigureServices(IServiceCollection services)
    {
        services.Configure<CookiePolicyOptions>(options =>
        {
            // This lambda determines whether user consent for non-essential cookies is needed for a given request.
            options.CheckConsentNeeded = context => true;
            options.MinimumSameSitePolicy = SameSiteMode.None;
        });

        services.AddDbContext<ApplicationDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("DefaultConnection")));
        services.AddIdentity<IdentityUser, IdentityRole>()
            //.AddDefaultUI(UIFramework.Bootstrap4)
            .AddEntityFrameworkStores<ApplicationDbContext>();

        services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

        services.AddSignalR();
    }

Does anyone know what I have to change in the connection string to be able to do the migration? 有人知道我必须更改连接字符串才能进行迁移吗? Thank you. 谢谢。

I have changed my conection string and code: 我更改了我的连接字符串和代码:

       services.AddDbContext<DbContext>(options =>
           options.UseMySql(Configuration.GetConnectionString("MysqlConnection"),
               mySqlOptions =>
               {
                   mySqlOptions.ServerVersion(new Version(10, 1, 38), Pomelo.EntityFrameworkCore.MySql.Infrastructure.ServerType.MySql); // replace with your Server Version and Type
               }));

"MysqlConnection": "Server=localhost;Database=ElectransUsers;User=root;Password=my_password;"

But I see the following error: 但是我看到以下错误:

在此处输入图片说明

Do you know what I'm doing wrong? 你知道我在做什么吗?

Consider using a MySQL connection provider. 考虑使用MySQL连接提供程序。 Example code snippet here. 示例代码段在这里。

services.AddDbContext<DbContext>(options =>
   options.UseMySql(configuration.GetConnectionString("MysqlConnection"),
       mySqlOptions =>
       {
        mySqlOptions.ServerVersion(new Version(5, 1, 73), ServerType.MySql); // replace with your Server Version and Type
       })

My Connection String 我的连接字符串

 "MysqlConnection": "server=194.36.12.123;port=3306;database=database_name_here;uid=user_name_here;password=password_here"

I am using Pomelo.EntityFrameworkCore.MySql Package 我正在使用Pomelo.EntityFrameworkCore.MySql

Here is documentation 这是文档

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

相关问题 不能在 ASP.NET 核心中使用我的 MySql 数据库和身份 - cant use my MySql database in ASP.NET Core with Identity 如何将.Net Core 身份表迁移到 MySql? - How do I migrate .Net Core Identity Tables to MySql? 使用MySQL数据库的ASP.NET身份给我的身份表一个错误的名称 - ASP.NET Identity using a MySQL Database gives my identity tables a wrong name 从docker-compose中的ASP.NET Core 2 Web应用程序连接到MySql 8 - Connecting to MySql 8 from ASP.NET Core 2 web app whithin docker-compose 无法迁移asp.net mvc 数据库 - Cannot migrate asp.net mvc database 如何在 asp.net 内核中编写高性能 sql 查询应用程序? - How to write a high performance sql query app in asp.net core? 我如何使用ASP.net将我的文本框值与数据库进行比较 - how can i compare my textbox value to my database using ASP.net MySQL 5.6全文搜索与ElasticSearch for ASP.NET 4.5 Web App - MySQL 5.6 Full Text Search vs ElasticSearch for my ASP.NET 4.5 Web App 如何将我的 ASP.Net 登录代码连接到 VB.Net 中的 MySQL 数据库 - How to connect my ASP.Net login code to MySQL database in VB.Net 尝试DropForeignKey时,MY.SQL ASP.NET Core Angular项目中的实体框架失败,并在CONSTRAINT附近的语法中出现MySqlException错误 - Entity Framework in MY.SQL ASP.NET Core Angular project fails with MySqlException error in syntax near CONSTRAINT when trying to DropForeignKey
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM