-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
EF Core 6.0 temporal table migration when altering computed column not generating correct script #27844
Comments
Had a similar issue while adding a new migration after altering a column name or adding a new column.
CodeOriginal entity looked like this: public class ExonerationDetermination : AuditEntity
{
public long Id { get; set; }
public string Determination { get; set; }
public string Reason { get; set; }
public string Comments { get; set; }
public virtual User CreatedByUser { get; set; }
} After modification: public class ExonerationDetermination : AuditEntity
{
public long Id { get; set; }
public string Determination { get; set; }
public string Reason { get; set; }
public string AdditionalComments { get; set; } // Modified
public virtual User CreatedByUser { get; set; }
public string PreviousStatus { get; set; } // Added
public string NewStatus { get; set; } // Added
} Generate migration with command:
When building and starting the project, the following error is displayed on the output window:
The three columns that are missing from the table 'PEJC.exoneration.DeterminationHistory' are precisely the ones we added/modified. We verified this in the ExpectedMigration script should be able to turn off versioning, alter/add columns as specified on the entity, then turn versioning back on. Additional InfoEF Core version: 6.0.9 |
Could someone post an example of what the correct migration script should be for such a situation (Add/Remove columns)? It would be useful as a workaround example for people waiting for a fix. |
/cc @maumar |
@James-Jackson-South The correct script in this case would need to make the table not system-versioned, add the computed column, then make it system-versioned again. However, after discussion we're not sure if this will work either. It may not be possible to make the table system-versioned if it has a computed column, and even if it is, it's not clear how that computed column would work when looking at historical data. What is the computed column definition that you want to use? |
EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it. BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions. |
Sorry @ajcvickers Just saw this. I wasn't using a computed column in my case but changing the column type. The workaround you suggested is the approach I eventually figured out, but it took me a rather long while to do so. |
…mputed column not generating correct script Working with computed column on a temporal table requires special processing - we need to disable the versioning, add the computed column to regular table and a column with the same name/type/position to the history table, but as a regular column. After all is done we re-enable versioning. Historical information on the computed column will be copied to the counterpart column in history table without issue. One thing that we can't do is modifying computed column SQL when table is temporal. What happens in case of CCSQL modification, we drop the column and create a new one with new CCSQL. This is not an issue for regular table, because the value is computed anyway, so old value is useless. But when we drop-create column, that column gets created at the last position in the table, and so the table no longer matches it's history table exactly (positions of columns may differ). We would have to drop+recreate column on a history table, but that results in losing historical data of that column. And that is valuable data, unlike for regular table. We could enable that scenario once/if we support table rebuilds. Fixes #27844
…mputed column not generating correct script Working with computed column on a temporal table requires special processing - we need to disable the versioning, add the computed column to regular table and a column with the same name/type/position to the history table, but as a regular column. After all is done we re-enable versioning. Historical information on the computed column will be copied to the counterpart column in history table without issue. One thing that we can't do is modifying computed column SQL when table is temporal. What happens in case of CCSQL modification, we drop the column and create a new one with new CCSQL. This is not an issue for regular table, because the value is computed anyway, so old value is useless. But when we drop-create column, that column gets created at the last position in the table, and so the table no longer matches it's history table exactly (positions of columns may differ). We would have to drop+recreate column on a history table, but that results in losing historical data of that column. And that is valuable data, unlike for regular table. We could enable that scenario once/if we support table rebuilds. Fixes #27844
…mputed column not generating correct script Working with computed column on a temporal table requires special processing - we need to disable the versioning, add the computed column to regular table and a column with the same name/type/position to the history table, but as a regular column. After all is done we re-enable versioning. Historical information on the computed column will be copied to the counterpart column in history table without issue. One thing that we can't do is modifying computed column SQL when table is temporal. What happens in case of CCSQL modification, we drop the column and create a new one with new CCSQL. This is not an issue for regular table, because the value is computed anyway, so old value is useless. But when we drop-create column, that column gets created at the last position in the table, and so the table no longer matches it's history table exactly (positions of columns may differ). We would have to drop+recreate column on a history table, but that results in losing historical data of that column. And that is valuable data, unlike for regular table. We could enable that scenario once/if we support table rebuilds. Fixes #27844
…mputed column not generating correct script (#32398) Working with computed column on a temporal table requires special processing - we need to disable the versioning, add the computed column to regular table and a column with the same name/type/position to the history table, but as a regular column. After all is done we re-enable versioning. Historical information on the computed column will be copied to the counterpart column in history table without issue. One thing that we can't do is modifying computed column SQL when table is temporal. What happens in case of CCSQL modification, we drop the column and create a new one with new CCSQL. This is not an issue for regular table, because the value is computed anyway, so old value is useless. But when we drop-create column, that column gets created at the last position in the table, and so the table no longer matches it's history table exactly (positions of columns may differ). We would have to drop+recreate column on a history table, but that results in losing historical data of that column. And that is valuable data, unlike for regular table. We could enable that scenario once/if we support table rebuilds. Fixes #27844
File a bug
Step 1 Make table temporal
Step 2 Add migration for that
Step 3 Add new computed column to the entity
step 4 Add Migration for altered column
setp 5 Generate script for migration
Include your code
added new computed column to existing Temporal Table
Generate migration
Generate migration script
When running migration in SQL Studio
Expected
Migration script to turn of versioning and alter both table and turn versioning on
EF Core version: 6.0.4
Database provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Target framework: (e.g. .NET 6.0)
Operating system: Windows
IDE: (e.g. Visual Studio 2022 17.2)
The text was updated successfully, but these errors were encountered: