System.InvalidOperationException: A schema "____dbschema" has been set for an object of type "CreateTableOperation" with the name of "tbl_tokencache". MySQL does not support the EF Core concept of schemas. Any schema property of any "MigrationOperation" must be null.
I totally no idea what's going on, this error throws when executing Update-database after generating the migration.
help... I don't know what does this erro mean so I don't know how to solve it.
Pomelo version: 3.1.1
MySql version: 5.7.20
Env: .NetCore 3.1
It means, that you seem to explicitly told Pomelo to use a schema with the name of ____dbschema somewhere in your code.
While in MySQL, a schema is just a synonym for a database, in EF Core, a schema is an organization unit inside a database, that e.g. you can assign tables to. For example, SQL Server supports different schemas inside a database (with the dbo schema being the default).
Since MySQL does not support the EF Core concept of schemas, your cannot use them with Pomelo.
To find the locations in your code, where you tell Pomelo to use the ____dbschema schema, just execute a search inside your solution for ____dbschema. Replace all occurrences of the string with null.
Since this happens in the CreateTableOperation of the table tbl_tokencache, it is likely that you either have the data annotation attribute Table declared for a model class like
```c#
[Table("tbl_tokencache", "____dbschema")] // should be [Table("tbl_tokencache")]
public class TokenCache
{
}
or are using a FluentAPI definition similar to the following:
```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TokenCache>()
.ToTable("tbl_tokencache", "____dbschema"); // should be .ToTable("tbl_tokencache")
}
It is however also possible, that you globally declared a default schema, that should be used for all model classes. Anyway, searching for ____dbschema will be the easiest way to find and replace all occurrences.
@lauxjpn oh so fast reply! thanks so so much, and the problem is resolved,
I found the problem:
in my BDAppDbContext class I don't know when i wrote this line in it:
modelBuilder.HasDefaultSchema("____dbschema");
then the generated migration file all has this:
migrationBuilder.CreateTable(
name: "tbl_tokencache",
schema: "____dbschema", // <-----
columns: table => new
{ .....
and after remove modelBuilder.HasDefaultSchema("____dbschema"); in my dbcontext class, the newly generated migration does not have the schema definition in it anymore, and everything work just fine.
Most helpful comment
It means, that you seem to explicitly told Pomelo to use a schema with the name of
____dbschemasomewhere in your code.While in MySQL, a schema is just a synonym for a database, in EF Core, a schema is an organization unit inside a database, that e.g. you can assign tables to. For example, SQL Server supports different schemas inside a database (with the
dboschema being the default).Since MySQL does not support the EF Core concept of schemas, your cannot use them with Pomelo.
To find the locations in your code, where you tell Pomelo to use the
____dbschemaschema, just execute a search inside your solution for____dbschema. Replace all occurrences of the string withnull.Since this happens in the
CreateTableOperationof the tabletbl_tokencache, it is likely that you either have the data annotation attributeTabledeclared for a model class like```c#
[Table("tbl_tokencache", "____dbschema")] // should be [Table("tbl_tokencache")]
public class TokenCache
{
}
It is however also possible, that you globally declared a default schema, that should be used for all model classes. Anyway, searching for
____dbschemawill be the easiest way to find and replace all occurrences.