Open pantonis opened 6 months ago
I have just updated to 8.0.1 [...]
@pantonis What version of Pomelo where you using before the upgrade?
ServerVersion.AutoDetect(connectionString)
opens a connection to the database server to retrieve the version of the server. If you add a migration and EF Core runs the code that executes ServerVersion.AutoDetect(connectionString)
, the database server referenced in the connection string must be available, or the ServerVersion
cannot get detected:
To generate the appropriate migrations, Pomelo needs to know the correct server version.
We generally do not recommend using ServerVersion.AutoDetect(connectionString)
in production code. We recommend to explicitly specify the ServerVersion
(which you now switched to), for example:
var optionsBuilder = new DbContextOptionsBuilder<MyDbContext>()
.UseMySql(
connectionString,
ServerVersion.Parse("10.10.1-mariadb"),
options =>
{
options.EnableRetryOnFailure();
options.MigrationsAssembly("MyAssembly.MariaDb");
});
We updated 8.X but we didn't use migrations on 8.0.0. We used migrations on 7.X and then on 8.0.1 where we hit the issue We have several clients each running different version of MariaDb. If we configure it somehow on each client then on each client update of MariaDb we need to update all of it microservices. This is very inconvienent as we have a lot of clients and dozens of microservices that need to be updated. Any other workaround
Pomelo needs to know the version of the database server (or at least the minimum server version it should support).
If you want to use ServerVersion.AutoDetect(connectionString)
, the database server that you reference in connectionString
must be reachable.
If you are having multiple clients with different database server versions, they are also using different connection strings. You can configure the connection string in a settings file, along with the server version string.
If you want to use the latest features for all your clients, you should generate an individual migration set for each client using their individual database server version.
If you don't care about the latest MariaDB features for all you clients, you could specify a static minimum server version that is <= the lowest server version of any of your clients. Then you can generate one set of migrations that works for all your clients.
If you want to use ServerVersion.AutoDetect(connectionString), the database server that you reference in connectionString must be reachable.
It is reachable. That is why I opened the ticket. Because with 7.0 version we didn't have any issues on that.
It is reachable. That is why I opened the ticket. Because with 7.0 version we didn't have any issues on that.
If I understand you correctly, you said earlier that you did not use migrations before 8.0.1
:
We updated 8.0 but we didn't use migrations on 8.0.0.
Did I understand you correctly, or did you use migrations before 8.0.1
?
Apologies for confusing you. We didn't use it for 8.0.0. We used it for version 7.X and then we upgraded to 8.0.1 and tried to use it on 8.0.1. This is where we noticed the issue. Let me correct my initial message
Please check, that you can indeed connect to the database from the same machine, that you execute the Add-Migration
command on.
Execute the following in a new console program on the same machine, that you execute the Add-Migration
command on (use <PackageReference Include="MySqlConnector" Version="2.3.5" />
):
var connectionString = "your connection string 100% identical to the one you use in your app";
using var connection = new MySqlConnection(connectionString);
connection.Open();
If it works, then move to the next section below. If it fails, then you don't have a working connection to the database referenced in your connection string.
There was a single change between 8.0.0
and 8.0.1
in regards to the ServerVersion.AutoDetect()
method, that added AutoEnlist = false
and Pooling = false
to the connection string.
Those changes should not have any influence on the matter, but if you want to verify this, you could revert those changes in a customized auto detect method:
public static ServerVersion CustomAutoDetect(string connectionString)
{
using var connection = new MySqlConnection(
new MySqlConnectionStringBuilder(connectionString)
{
Database = string.Empty,
// AutoEnlist = false,
// Pooling = false,
}.ConnectionString);
connection.Open();
return Parse(connection.ServerVersion);
}
You then call this CustomAutoDetect(connectionString)
method instead of the ServerVersion.AutoDetect(connectionString)
one that ships with Pomelo.
If it suddenly works, than ServerVersion.AutoDetect(connectionString)
is indeed the issue. Otherwise, it is not.
@pantonis Did you try the steps I outlined in my previous post?
@lauxjpn It indeed worked for me, I called the CustomAutoDetect instead.
Steps to reproduce
Ideally include a complete code listing that we can run to reproduce the issue. Alternatively, you can provide a project/solution that we can run.
The issue
I am trying to run Add-Migration command and I get
Further technical details
This is my code
As soon as I change it to this
It works. I have just updated to 8.0.1 so I don't know if this is the cause
MySQL version: 10.10.1 (MariaDb) Operating system: Windows 10 Pomelo.EntityFrameworkCore.MySql version: 8.0.1 Microsoft.AspNetCore.App version: 8.0.2
Other details about my project setup: