-
Notifications
You must be signed in to change notification settings - Fork 383
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
Database scaffolding produces wrong code when tables have datetime/timestamp columns with default value CURRENT_TIMESTAMP #703
Comments
The logic for defaults in MySqlDatabaseModelFactory class is currently rudimentary as it assumes default is a string. Type checking will be required, i.e. varchar, int, enum etc. to determine if quotes are required (and to use escaping if needed) and also following rules in Data Type Default Values. |
lauxjpn
added a commit
to lauxjpn/Pomelo.EntityFrameworkCore.MySql
that referenced
this issue
Oct 24, 2019
Fixed in #896. |
I find that the codes below can work fine and avoid the bug before new version releases. protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<TimestampTable>(entity =>
{
entity.Property(e => e.Dt)
.HasDefaultValueSql("CURRENT_TIMESTAMP()")
.ValueGeneratedOnAddOrUpdate();
entity.Property(e => e.Ts)
.HasDefaultValueSql("CURRENT_TIMESTAMP()")
.ValueGeneratedOnAddOrUpdate();
});
} |
lauxjpn
added a commit
that referenced
this issue
Oct 27, 2019
* Add support to reverse engineer views. Add comments for tables and columns. Improve handling of default values. * Handle the `CURRENT_TIMESTAMP` default value for `timestamp` columns correctly. Fixes #703 * Correctly implement `CURRENT_TIMESTAMP` with `ON UPDATE` clauses. Introduce a workaround for the missing EF Core handling of `ValueGenerated.OnUpdate`. Fixes #877 * Remove unnecessary code Can probably remove this code as it only applies to Release Candidate not General Availability versions. https://bugs.mysql.com/bug.php?id=89793 >The NON_UNIQUE column in the INFORMATION_SCHEMA.STATISTICS table had type BIGINT prior to MySQL 8.0, but became VARCHAR in MySQL 8.0 with the introduction of the data dictionary. The NON_UNIQUE column now has an integer type again (INT because the column need not be as large as BIGINT). * Correctly map `unsigned` database types with precision, scale, size or display width to CLR types. * Fix table/view determination. * Support views in `MySqlDatabaseCleaner`. * Fix some Timestamp/RowVersion issues. Still depends on dotnet/efcore#18592 Addresses #792
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Steps to reproduce
Create a table like this one:
run:
The issue
Pomelo sets the default value
'CURRENT_TIMESTAMP'
(string) instead ofCURRENT_TIMESTAMP
The generated code is:
Trying to recreate the database with
myDbContext.Database.EnsureCreated()
will throw an exceptionbecause the default value for the
timestamp
column is'CURRENT_TIMESTAMP'
.EFCore Log:
Exception message:
Stack trace:
Further technical details
MySQL version:
5.7.20
Operating system:
CentOS 7.4
Pomelo.EntityFrameworkCore.MySql version:
2.1.2
The text was updated successfully, but these errors were encountered: