-
-
Notifications
You must be signed in to change notification settings - Fork 395
Add migration is always generating code for row version property. #1036
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
Comments
Looks correct to me. You used the CREATE TABLE `SubscriptionCharacterLocation` (
`RowVersion` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
); What is it you would expect in your scenario and why do you think the current behavior is/could be a problem? |
Hi, yes it is correct but it always getting generated on each add migration. If I do other changes it will add the code shown in the issue section. Should it be like that? |
No, this behavior would be unexpected. I will look into that. |
I have exactly the same problem.
|
Making the //
// Using Data Annotations:
//
public class MyEntity
{
[Required] // <-- Non-Nullable
[Timestamp]
public byte[] RowVersion { get; set; }
}
//
// Using FluentAPI:
//
public class MyEntity
{
public byte[] RowVersion { get; set; }
}
public class MyContext : DbContext
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>(entity =>
{
entity.Property("RowVersion")
.IsRequired() // <-- Non-Nullable
.IsConcurrencyToken()
.ValueGeneratedOnAddOrUpdate();
});
}
} |
After updating EF Core and Pomelo MySQL to version 7, I would get an error on SaveChanges stating invalid SQL on RETURNING RowVersion, so I tried the mentioned workaround. I'm using MariaDB 10.3. In my model I have the following, which worked fine with everything on version 6:
After changing it to the above workaround like so:
I'm getting the following error trying to apply the migration:
|
How did you resolve this issue? I have the same error |
The project reached EOL, so I stayed at EF6 in the end. However, looking at the migrations and latest code, I did switch the RowVersion to be not nullable and force a default:
|
Thanks for the answer, but this didn't work on .NET 9.
Generated:
This also works, but I don't know how to generate something like this automatically
I hope it helped someone |
Steps to reproduce
Add-Migration
The issue
RowVersion is always being generated, no issues however with running the solution.
Further technical details
MySQL version:
new Version(10, 1, 31), ServerType.MariaDb
Operating system: Windows 10
Pomelo.EntityFrameworkCore.MySql version: 3.1.1
Microsoft.AspNetCore.App version: 3.1
Other details about my project setup:
The text was updated successfully, but these errors were encountered: