New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mysql exception using SystemMethods.NewGuid #1590
Comments
I am not a MySQL expert, but it looks like MySQL changed the rules regarding allowing functions/expressions as default values in:
That said, it looks like the MySql Generator is also spuriously adding a "SELECT" in front of the UUID() value: @spiana - what version of MySQL are you using? It sounds like even if we change this , if you're not on MySQL 8.0.13 or later, it still won't work. @fubar-coder - any idea why Two review questions:
The documentation for MySQL UUID values is longwinded and dense. See: https://dev.mysql.com/doc/refman/8.0/en/miscellaneous-functions.html#function_uuid-to-bin - the takeaways are:
|
@jzabroski Sorry, no idea |
All good. I was able to stand up MySQL to test. The following works well: drop table if exists scientist;
create table scientist (id integer, firstname varchar(100), lastname varchar(100), sid varchar(50) default (BIN_TO_UUID(UUID_TO_BIN(uuid(),1),1)));
insert into scientist (id, firstname, lastname, sid) values (1, 'albert', 'einstein', default);
insert into scientist (id, firstname, lastname, sid) values (2, 'isaac', 'newton', default);
insert into scientist (id, firstname, lastname, sid) values (3, 'marie', 'curie', default);
select * from scientist; as does drop table if exists scientist;
create table scientist (id integer, firstname varchar(100), lastname varchar(100), sid varchar(50) default (uuid()));
insert into scientist (id, firstname, lastname, sid) values (1, 'albert', 'einstein', default);
insert into scientist (id, firstname, lastname, sid) values (2, 'isaac', 'newton', default);
insert into scientist (id, firstname, lastname, sid) values (3, 'marie', 'curie', default);
select * from scientist; I think, based on my reading, that UUID() may be preferable by default, perhaps with an FAQ added in the docs for now for using the RawSql helper to use a more complex expression like |
An additional point is that Microsoft T-SQL
In addition, RFC4122 Section 4.1.1 notes:
Also, RC4122 Section 4.1.3 describes the Version 1 format that MySQL uses:
|
@jzabroski I am now testing using Mysql version 8.0.27 but I have encountered the same problem on version 5.7. |
@spiana Just wondering if you know otherwise as to whether 5.7 should support this. I'm not a MySQL expert. The MySQL docs are super longwinded, like reading a John Updike novel. |
@jzabroski. No, you're probably right, I got confused about the version. I also found some documentation where it says that functions as default were introduced in version 8.0.13. |
Describe the bug
Mysql exception using SystemMethods.NewGuid
To Reproduce
create a table with a column of type varchar using default SystemMethods.NewGuid
Create
.Table("test")
.WithColumn("Id").AsInt32().PrimaryKey().Identity()
.WithColumn("code").AsString(50).NotNullable()
.WithColumn("uuid").AsString(50).WithDefault(SystemMethods.NewGuid);
When you execute the migration you will get the following Exception
MySql.Data.MySqlClient.MySqlException
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 'SELECT UUID()), CONSTRAINT
PK_test
PRIMARY KEY (Id
)) ENGINE = INNODB' at line 1at 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.ExecuteReader()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery()
at FluentMigrator.Runner.Processors.MySql.MySqlProcessor.Process(String sql)
at FluentMigrator.Runner.Processors.ProcessorBase.Process(CreateTableExpression expression)
at FluentMigrator.Expressions.CreateTableExpression.ExecuteWith(IMigrationProcessor processor)
at FluentMigrator.Runner.MigrationRunner.<>c__DisplayClass80_0.b__1()
at FluentMigrator.Runner.StopWatch.Time(Action action)
at FluentMigrator.Runner.MigrationRunner.ExecuteExpressions(ICollection
1 expressions) at FluentMigrator.Runner.MigrationRunner.ExecuteMigration(IMigration migration, Action
2 getExpressions)at FluentMigrator.Runner.MigrationRunner.ApplyMigrationUp(IMigrationInfo migrationInfo, Boolean useTransaction)
at FluentMigrator.Runner.MigrationRunner.MigrateUp(Int64 targetVersion, Boolean useAutomaticTransactionManagement)
at FluentMigrator.Runner.MigrationRunner.MigrateUp(Boolean useAutomaticTransactionManagement)
at FluentMigrator.Runner.MigrationRunner.MigrateUp()
Information (please complete the following information):
The text was updated successfully, but these errors were encountered: