如何从我的 linux 上的 asp.net 核心应用程序迁移我的表 [英] How to migrate my tables from my asp.net core app on linux
问题描述
我制作了一个可以在我的 Windows 机器上完美运行的 asp.net 核心应用程序.我需要在 Linux 机器上部署这个应用程序.将我的表迁移到 Linux 机器上的 MySQL 服务器时,我的问题出现了.我有用于生产目的的 Linux 机器,我需要 MySQL 服务器供用户处理.我已经创建了一个数据库,但是当我运行命令 dotnet ef database update 将我的表迁移到这个数据库时,我看到以下错误:
I have made an asp.net core app that runs perfectly in my windows machine. I need to deploy this app on a Linux machine. My problem comes when migrating my tables into MySQL server on the Linux machine. I have the Linux machine for production purposes and I need MySQL server for users handling. 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:
用于连接到我的数据库的连接字符串如下:
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"
},
如果我更改写入 localhost 而不是 localdb 的连接字符串,我会看到以下错误:
If I change the connection string writing localhost instead of localdb I see the following error:
如果我删除 mssqllocaldb,我会看到以下错误:
If I remove mssqllocaldb I see the following error:
我在 Startup.cs 脚本中的 Configure 方法如下:
And my Configure method in the Startup.cs script is the following:
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;"
但我看到以下错误:
你知道我做错了什么吗?
Do you know what I'm doing wrong?
推荐答案
考虑使用 MySQL 连接提供程序.示例代码片段在这里.
Consider using a MySQL connection provider. 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
})
我的连接字符串
"MysqlConnection": "server=194.36.12.123;port=3306;database=database_name_here;uid=user_name_here;password=password_here"
我正在使用 Pomelo.EntityFrameworkCore.MySql
包
这是文档
这篇关于如何从我的 linux 上的 asp.net 核心应用程序迁移我的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!