[英]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.