Open Trevortni opened 2 years ago
See https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/pull/982 regarding schema options. This is also somewhat related to https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/1192.
I've decided to explore the possibility of using the SchemaNameTranslator
to output the concatenated schema
and name
: `schemaName`.`name`
, but I run into the same issue I get if I try to include the schema in the name in the first place: the result of the SchemaNameTranslator
gets passed to base.DelimitIdentifier
, which replaces the internal backticks with doubled backticks.
PR's are welcome and appreciated. A check could be made for identifier that is already delimited.
Are you thinking that if it's already delimited, then we could safely assume that it's also already escaped?
Steps to reproduce
Create a migration that calls CreateTable with constraints containing a ForeignKey, such that principalKey is set to a schema that exists in the database and contains the table and column specified in principalTable and principalColumn.
The issue
Foreign key cannot be added to the database, with the error message below.
On inspection, it appears that the problem is in
DelimitIdentifier(string name, string schema)
inMySqlSqlGeneratorHelper.cs
, which callsbase.DelimitIdentifier
with the results ofGetObjectName(name, schema)
andGetSchemaName(name, schema)
; the first of which calls aSchemaNameTranslator
if one is found, otherwise it drops theschema
and just returns thename
; and the latter of which just returnsnull
. Either way,schema
is simply ignored.Further technical details
MySQL version: 5.7.38 Operating system: Windows 10 Pomelo.EntityFrameworkCore.MySql version: 6.0.2 Microsoft.AspNetCore.App version: .NET 6.0