Bug #84012 Exception caused by Code First Migrations-have an error in your SQL syntax
Description:
I’m trying to use EF Code First Migrations to add a new field to the model and migrate that change to MySQL database. I’m getting the exception.
Exception message:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near '/1/1 ??12:00:00' at line 1
Stack trace:
```csharp
MySql.Data.MySqlClient.MySqlException: You have an error in your SQL syntax; check the manual that corresponds to your MyS
QL server version for the right syntax to use near '/1/1 ??12:00:00' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, String ex
ecuteMethod, IReadOnlyDictionary`2 parameterValues, Boolean openConnection, Boolean closeConnection)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteNonQuery(IRelationalConnection connection, I
ReadOnlyDictionary`2 parameterValues, Boolean manageConnection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.MigrationCommandExecutor.ExecuteNonQuery(IEnumerable`1 migrationCo
mmands, IRelationalConnection connection)
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.Design.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType)
at Microsoft.EntityFrameworkCore.Tools.Cli.DatabaseUpdateCommand.<>c__DisplayClass0_0.<Configure>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Cli.Program.Main(String[] args)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax
to use near '/1/1 ??12:00:00' at line 1
```
How to repeat:
Steps to reproduce:
1. I added a `public DateTime BirthDate` new property to the model.
2. enter command: `dotnet ef migrations add NewField_BirthDate`.
3. enter command: `dotnet ef database update`.
4. get the exception.
In `Migrations` folder on my project, `BirthDate` defaultValue is DateTime(1,1,1,0,…) in `Up` method.
Portions of this website are copyright © 2001, 2002 The PHP Group
Page generated in 0.041 sec. using MySQL 8.4.7-u6-cloud
Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the
respective copyright holders.
It is not reviewed in advance
by Oracle and does not necessarily represent the opinion of
Oracle or any other party.