问题
I right-clicked on a column name in a CREATE TABLE script and selected Refactor | Rename. It renamed the column and the expected entry appears in the refactorlog XML file.
However, when I run a Schema Comparison from my project to my database and then generate the script, the script contains no mention of a refactoring and wants to drop the existing column name and add it with the new name.
I have no _RefactorLog table in this database. The deployment script does not attempt to create one. It's like it is completely ignoring the presence of the refactorlog XML file.
The XML file does start with the expected xmlns:
<?xml version="1.0" encoding="utf-8"?>
<Operations Version="1.0" xmlns="http://schemas.microsoft.com/sqlserver/dac/Serialization/2012/02">
<Operation Name="Rename Refactor" Key="4c6a080c-0626-4824-9b59-8ecfd491319a" ChangeDateTime="11/18/2013 19:03:13">
<Property Name="ElementName" Value="[dbo].[Report].[Name]" />
<Property Name="ElementType" Value="SqlSimpleColumn" />
<Property Name="ParentElementName" Value="[dbo].[Report]" />
<Property Name="ParentElementType" Value="SqlTable" />
<Property Name="NewName" Value="[DisplayName]" />
</Operation>
</Operations>
I see this in the deployment script:
/*
The column [dbo].[Report].[Name] is being dropped, data loss could occur.
The column [dbo].[Report].[DisplayName] on table [dbo].[Report] must be added,
but the column has no default value and does not allow NULL values. If the table
contains data, the ALTER script will not work. To avoid this issue you must
either: add a default value to the column, mark it as allowing NULL values, or
enable the generation of smart-defaults as a deployment option.
*/
How can I get this working?
Note: The project file (and all other files) was saved before running the Schema Comparison. The refactorlog file was pre-existing, with about a half-dozen entries from the last time I used the refactor rename feature about a year ago, in addition to the two entries that are new from the current set of changes. It's not that this feature has never worked for me, it's that it no longer works when it used to work.
I am using VS 2012 Premium 11.0.60610.01 Update 3 with SSDT 11.1.31009.1.
Thanks, Mark
回答1:
I am not sure if this is the answer you need, Mark, but my solution to this problem is described here: SQL Server Data Tools Ignores Refactor on Schema Compare. Essentially, SQL Data Tools maintains metadata in the database to ensure that a refactor is only performed once. I'd be interested to know if this was the source of your problem. If not, did you ever find a correct solution?
回答2:
I just ran into this same issue, none of the suggestions worked out. It turns out that - in my case, at least - the Build Action property for the refactor log file was set to "None" - it should be set to "RefactorLog". Once I changed this setting and re-generated the script, all the associated entries in the log were addressed in the generated scripts.
Hope this helps someone.
来源:https://stackoverflow.com/questions/20082079/ssdt-refactor-rename-is-ignored-by-the-schema-comparison-script-generation