2

im using mysql database with EF core .

i use Identity Schema to my existed MySql database , after doing a migration , update database generate this :

"A schema "Identity" has been set for an object of type "CreateTableOperation" with the name of "Role". MySQL does not support the EF Core concept of schemas. Any schema property of any "MigrationOperation" must be null. This behavior can be changed by setting the SchemaBehavior option in the UseMySql call."

error pic So how to set the schemabehavior option . With gratitude.

3 Answers 3

3

Update your service registrator (Startup.cs) and modify the DB context to set the SchemaBehavior option as one of the following:

// Throw an exception, if a schema is being used. This is the default.
options.UseMySql(myConnectionString, b => b.SchemaBehavior(MySqlSchemaBehavior.Throw))

// Silently ignore any schema definitions.
options.UseMySql(myConnectionString, b => b.SchemaBehavior(MySqlSchemaBehavior.Ignore))

// Use the specified translator delegate to translate from an input schema and object name to
// an output object name whenever a schema is being used.
options.UseMySql(myConnectionString, b => b.SchemaBehavior(MySqlSchemaBehavior.Translate,
    (schema, entity) => $"{schema ?? "dbo"}_{entity}"))
Sign up to request clarification or add additional context in comments.

Comments

0
// Just ignore all schemas:


optionsBuilder
    .UseMySql(
        connectionString,
        serverVersion,
        o => o.SchemaBehavior(MySqlSchemaBehavior.Ignore))

// Translate schemas into a table name prefix like `schema_table`:


optionsBuilder
    .UseMySql(
        connectionString,
        serverVersion,
        o => o.SchemaBehavior(MySqlSchemaBehavior.Translate, (schema, table) => $" 
        {schema}_{table}"))

Comments

0

// You can Ignore all schemas by adding this code in your program.cs file:

builder.Services.AddDbContextPool(options => { options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString) ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found."), b => b.SchemaBehavior(MySqlSchemaBehavior.Ignore)); // Set the SchemaBehavior option here });

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.