我继承了数据库项目。
它有很多表和st过程的create语句。 由于某种原因,所有表都没有外键。
所以我正在为表创建外键,当我发布时,我看到生成了ALTER TABLE
但数据不干净,因此在发布过程中会产生错误。
我发现我可以拥有预部署脚本(Build Action = PreDeploy) 所以我添加了一行来支持外键
delete from [AccountBalance] where UserId not in (select userid from [user])
但是当我生成发布脚本时,它就不存在了。
为什么?
更新 发送项目代码
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<SSDTExists Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')">True</SSDTExists>
<VisualStudioVersion Condition="'$(SSDTExists)' == ''">10.0</VisualStudioVersion>
<IncludeSchemaNameInFileName>False</IncludeSchemaNameInFileName>
<TargetFrameworkProfile />
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProjectName>SAK</SccProjectName>
<UpgradedFromDBP>True</UpgradedFromDBP>
<Name>dbpProjectName</Name>
<SchemaVersion>2.0</SchemaVersion>
<ProjectVersion>4.1</ProjectVersion>
<ProjectGuid>{f43cbd44-bbab-48f6-949d-47c9042bb406}</ProjectGuid>
<DSP>Microsoft.Data.Tools.Schema.Sql.Sql100DatabaseSchemaProvider</DSP>
<OutputType>Database</OutputType>
<RootPath>
</RootPath>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
<SccProjectName>SAK</SccProjectName>
<UpgradedFromDBP>True</UpgradedFromDBP>
<RootNamespace>dbpProjectName</RootNamespace>
<PostUpgradeAddToSCC>;C:\Users\travis\Documents\FR\Projects\Fr\Trunk\Fr.Database\Fr.Database.sqlproj;C:\Users\travis\Documents\FR\Projects\Fr\Trunk\Fr.Database\Connections.txt</PostUpgradeAddToSCC>
<SccProvider>
</SccProvider>
<SccAuxPath>
</SccAuxPath>
<SccLocalPath>
</SccLocalPath>
<SccProjectName>
</SccProjectName>
<UpgradedFromDBP>True</UpgradedFromDBP>
<AssemblyName>dbpProjectName</AssemblyName>
<ModelCollation>1033, CI</ModelCollation>
<DefaultFileStructure>BySchemaAndSchemaType</DefaultFileStructure>
<DeployToDatabase>True</DeployToDatabase>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetLanguage>CS</TargetLanguage>
<AppDesignerFolder>Properties</AppDesignerFolder>
<SqlServerVerification>False</SqlServerVerification>
<TargetDatabaseSet>True</TargetDatabaseSet>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<OutputPath>bin\Release\</OutputPath>
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>False</TreatWarningsAsErrors>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<!-- VS10 without SP1 will not have VisualStudioVersion set, so do that here -->
<PropertyGroup />
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Integration|AnyCPU' ">
<OutputPath>bin\Debug\</OutputPath>
<BuildScriptName>$(MSBuildProjectName).sql</BuildScriptName>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
<ItemGroup>
<Folder Include="Properties" />
<Folder Include="Cleanup Scripts" />
<Folder Include="Pre-Deploy" />
<Folder Include="Post-Deploy" />
</ItemGroup>
<ItemGroup>
<Folder Include="Change Scripts" />
<Folder Include="Create Scripts" />
<Folder Include="Data" />
<Folder Include="Functions" />
<Folder Include="Queries" />
<Folder Include="Views" />
<Folder Include="Properties" />
</ItemGroup>
<ItemGroup>
<Build Include="Create Scripts\AccountBalance.sql" />
<Build Include="Create Scripts\AccountTransaction.sql" />
<Build Include="Create Scripts\ActivityType.sql" />
<Build Include="Create Scripts\Bl.sql" />
<Build Include="Create Scripts\Butter.sql" />
<Build Include="Create Scripts\ButterStash.sql" />
<Build Include="Create Scripts\ButterTransfer.sql" />
<Build Include="Create Scripts\City.sql" />
<Build Include="Create Scripts\Contact.sql" />
<Build Include="Create Scripts\Fan.sql" />
<Build Include="Create Scripts\Friend.sql" />
<Build Include="Create Scripts\Fr.sql" />
<Build Include="Create Scripts\FrLevel.sql" />
<Build Include="Create Scripts\FrLevelQuestion.sql" />
<Build Include="Create Scripts\FrLevelQuestionResult.sql" />
<Build Include="Create Scripts\FrLevelStatus.sql" />
<Build Include="Create Scripts\FrMessage.sql" />
<Build Include="Create Scripts\FrPlayer.sql" />
<Build Include="Create Scripts\FrPlayerStatus.sql" />
<Build Include="Create Scripts\FrQuestion.sql" />
<Build Include="Create Scripts\FrStatus.sql" />
<Build Include="Create Scripts\Invite.sql" />
<Build Include="Create Scripts\InviteSource.sql" />
<Build Include="Create Scripts\InviteType.sql" />
<Build Include="Create Scripts\Lookup.sql" />
<Build Include="Create Scripts\Message.sql" />
<Build Include="Create Scripts\MessageActivity.sql" />
<Build Include="Create Scripts\MessageRecipient.sql" />
<Build Include="Create Scripts\MessageType.sql" />
<Build Include="Create Scripts\PasswordReset.sql" />
<Build Include="Create Scripts\Prize.sql" />
<Build Include="Create Scripts\PrizeType.sql" />
<Build Include="Create Scripts\TransactionType.sql" />
<Build Include="Create Scripts\User.sql" />
<Build Include="Create Scripts\UserActivity.sql" />
<Build Include="Create Scripts\UserAlternateCountryRequest.sql" />
<Build Include="Create Scripts\UserLogin.sql" />
<Build Include="Create Scripts\UserMedia.sql" />
<Build Include="Create Scripts\UserValidation.sql" />
<NotInBuild Include="Data\ActivityType.sql" />
<NotInBuild Include="Data\ButterValues.sql" />
<NotInBuild Include="Data\CityValues.sql" />
<NotInBuild Include="Data\LookupValues.sql" />
<NotInBuild Include="Data\User_TestData.sql" />
<Build Include="Functions\fn_GetDisplayName.sql" />
<Build Include="Functions\fn_ListToTable.sql" />
<Build Include="Queries\AccountBalanceGet.sql" />
<Build Include="Queries\AccountTransactionCreate.sql" />
<Build Include="Queries\AccountTransactionHasCreditPurchase.sql" />
<Build Include="Queries\BlCreate.sql" />
<Build Include="Queries\BlGetLatest.sql" />
<Build Include="Queries\BlsGet.sql" />
<Build Include="Queries\ButterGet.sql" />
<Build Include="Queries\ButterGetAll.sql" />
<Build Include="Queries\ButterMostPopularGet.sql" />
<Build Include="Queries\ButterStashCreate.sql" />
<Build Include="Queries\ButterStashDelete.sql" />
<Build Include="Queries\ButterStashGet.sql" />
<Build Include="Queries\ButterTransferCreate.sql" />
<Build Include="Queries\ButterTransferGet.sql" />
<Build Include="Queries\CitySearchByName.sql" />
<Build Include="Queries\FanCreate.sql" />
<Build Include="Queries\FanDelete.sql" />
<Build Include="Queries\FanSearch.sql" />
<Build Include="Queries\FansGet.sql" />
<Build Include="Queries\FansOfUserGet.sql" />
<Build Include="Queries\FansOfUserSearch.sql" />
<Build Include="Queries\FriendCreate.sql" />
<Build Include="Queries\FriendDelete.sql" />
<Build Include="Queries\FriendSearch.sql" />
<Build Include="Queries\FriendSearchByName.sql" />
<Build Include="Queries\FriendsGet.sql" />
<Build Include="Queries\FrCreate.sql" />
<Build Include="Queries\FrDelete.sql" />
<Build Include="Queries\FrGet.sql" />
<Build Include="Queries\FrGetAll.sql" />
<Build Include="Queries\FrGetLevelExpired.sql" />
<Build Include="Queries\FrLevelCreate.sql" />
<Build Include="Queries\FrLevelGet.sql" />
<Build Include="Queries\FrLevelIsComplete.sql" />
<Build Include="Queries\FrLevelQuestionClear.sql" />
<Build Include="Queries\FrLevelQuestionCreate.sql" />
<Build Include="Queries\FrLevelQuestionResultUpsert.sql" />
<Build Include="Queries\FrLevelStatusUpdate.sql" />
<Build Include="Queries\FrLevelUpdate.sql" />
<Build Include="Queries\FrMessageCreate.sql" />
<Build Include="Queries\FrMessageDelete.sql" />
<Build Include="Queries\FrMessageGet.sql" />
<Build Include="Queries\FrMessagesGet.sql" />
<Build Include="Queries\FrPlayerAdd.sql" />
<Build Include="Queries\FrPlayerRemove.sql" />
<Build Include="Queries\FrPlayerUpdate.sql" />
<Build Include="Queries\FrQuestionGetAll.sql" />
<Build Include="Queries\FrStart.sql" />
<Build Include="Queries\FrUpdate.sql" />
<Build Include="Queries\FrUpdateFringle.sql" />
<Build Include="Queries\InviteCreate.sql" />
<Build Include="Queries\InviteDelete.sql" />
<Build Include="Queries\InviteDeleteByUserId.sql" />
<Build Include="Queries\InviteGet.sql" />
<Build Include="Queries\InviteGetAll.sql" />
<Build Include="Queries\InviteGetByFrId.sql" />
<Build Include="Queries\InviteGetByUserId.sql" />
<Build Include="Queries\InviteGetSentAll.sql" />
<Build Include="Queries\InviteUpdateAssociateEmailToUserId.sql" />
<Build Include="Queries\InviteUpdateInviteStatus.sql" />
<Build Include="Queries\InviteUpdateUserId.sql" />
<Build Include="Queries\LookupsGet.sql" />
<Build Include="Queries\MessageCreate.sql" />
<Build Include="Queries\MessageDelete.sql" />
<Build Include="Queries\MessageGet.sql" />
<Build Include="Queries\MessageRecipientActionUpdate.sql" />
<Build Include="Queries\MessageRecipientUpdate.sql" />
<Build Include="Queries\MessagesGet.sql" />
<Build Include="Queries\MessagesGetSent.sql" />
<Build Include="Queries\MessageThreadGet.sql" />
<Build Include="Queries\MessageUnreadCountGet.sql" />
<Build Include="Queries\PasswordResetCreate.sql" />
<Build Include="Queries\PasswordResetDelete.sql" />
<Build Include="Queries\PasswordResetGet.sql" />
<Build Include="Queries\PrizeGet.sql" />
<Build Include="Queries\PrizesGet.sql" />
<Build Include="Queries\UserActivityCreate.sql" />
<Build Include="Queries\UserActivityForRelatedUsersGet.sql" />
<Build Include="Queries\UserActivityGet.sql" />
<Build Include="Queries\UserAlternateCountryRequestCreate.sql" />
<Build Include="Queries\UserBrowse.sql" />
<Build Include="Queries\UserCreate.sql" />
<Build Include="Queries\UserFrNameExists.sql" />
<Build Include="Queries\UserGet.sql" />
<Build Include="Queries\UserGetByEmail.sql" />
<Build Include="Queries\UserHasBeenFrer.sql" />
<Build Include="Queries\UserLoginInsert.sql" />
<Build Include="Queries\UserMediaDelete.sql" />
<Build Include="Queries\UserMediaGet.sql" />
<Build Include="Queries\UserMediaList.sql" />
<Build Include="Queries\UserMediaUpsert.sql" />
<Build Include="Queries\UserPasswordUpdate.sql" />
<Build Include="Queries\UserProfileGet.sql" />
<Build Include="Queries\UserProfileUpdate.sql" />
<Build Include="Queries\UserSearch.sql" />
<Build Include="Queries\UserUpdate.sql" />
<Build Include="Queries\UserValidationGet.sql" />
<Build Include="Queries\UserValidationGetByUserId.sql" />
<Build Include="Views\UserSummaryView.sql" />
<Build Include="Create Scripts\MessageTypeGroup.sql" />
<None Include="Data\MessageTypeGroup.sql" />
<Build Include="Queries\UserGetByFbId.sql" />
<PreDeploy Include="Pre-Deploy\Script.PreDeployment1.sql" />
</ItemGroup>
<ItemGroup>
<None Include="Data\Prize.sql" />
<None Include="Data\PrizeType.sql" />
<None Include="Data\TransactionType.sql" />
<None Include="Cleanup Scripts\CleanFrRelatedTables.sql" />
<None Include="Data\FrLevelStatus.sql" />
<None Include="Data\FrPlayerStatus.sql" />
<None Include="Data\FrQuestion.sql" />
<None Include="Data\FrStatus.sql" />
<None Include="Data\InviteSource.sql" />
<None Include="Data\InviteType.sql" />
<None Include="Data\MessageActivity.sql" />
<None Include="Data\MessageType.sql" />
<None Include="Data\FrReminderTypeValues.sql" />
<None Include="Fr.DevDatabase.publish.xml" />
<None Include="Fr.IntegrationDatabase.publish.xml" />
<None Include="Pre-Deploy\Script1.sql" />
</ItemGroup>
<ItemGroup>
<Build Include="Create Scripts\Feedback.sql" />
<Build Include="Queries\FeedbackCreate.sql" />
<Build Include="Create Scripts\FrReminder.sql" />
<Build Include="Create Scripts\FrReminderType.sql" />
<Build Include="Queries\FrReminderCreate.sql" />
<Build Include="Queries\FrReminderUpdate.sql" />
<Build Include="Queries\FrReminderDelete.sql" />
<Build Include="Queries\FrReminderUpdateUserId.sql" />
<Build Include="Queries\FrReminderGetPendingWarnings.sql" />
<Build Include="Queries\FrReminderGetPendingExpiries.sql" />
<Build Include="Queries\BlsFromFriendsGet.sql" />
<Build Include="Create Scripts\Counter.sql" />
<Build Include="Queries\CounterGet.sql" />
<Build Include="Queries\CounterSet.sql" />
<Build Include="Queries\UserActivityHide.sql" />
<Build Include="Queries\BlDelete.sql" />
<Build Include="Create Scripts\UserBl.sql" />
<Build Include="Queries\UserBlGet.sql" />
<Build Include="Queries\UserBlCreate.sql" />
<Build Include="Queries\UserBlDelete.sql" />
<Build Include="Queries\BlGet.sql" />
<Build Include="Queries\AccountTransactionGetByFr.sql" />
</ItemGroup>
<ItemGroup>
<RefactorLog Include="Fr.Database.refactorlog" />
</ItemGroup>
</Project>
答案 0 :(得分:1)
你知道吗...
这可能不是你的问题,但我只是被这个困了大约20分钟,事实证明愚蠢的事情(VS)不会在ACTUAL BUILD之外应用这些东西(所以它必须采取构建脚本“按惯例”,只需将它们自动添加到发布脚本中......
所以,如果你像我一样,直到现在并没有真正理解“配置管理器”的重要性那么你可能没有注意到由于某种原因你的项目(dtabase项目)没有检查“BUILD”在此配置(DEBUG / RELEASE)中,将生成脚本,但不包括前/后部署脚本......
您在输出窗口中获得的所有内容都是“跳过”消息,如果您在解决方案中有很多其他项目,这很容易错过!
无论如何只是张贴这个因为它可能对某人有帮助。