sql-server - 使用 VS 2017 数据库项目创建数据库时删除索引时出错
问题描述
我有一个在 VS 2017 中创建的数据库项目。我已经对其进行了大幅更改,包括将列移动到不同的表等。
然后我删除了 bin & obj 文件夹。我还去了 C:\Users\david\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\ProjectsV13,在正在运行的进程中杀死了 sqlserver.exe,然后删除了该文件夹中的所有文件。
我在构建时仍然得到以下信息:
------ Build started: Project: Database1, Configuration: Debug Any CPU ------
Loading project references...
Loading project files...
Building the project model and resolving object interdependencies...
Validating the project model...
Writing model to C:\git\Store\Database1\obj\Debug\Model.xml...
Database1 -> C:\git\Store\Database1\bin\Debug\Database1.dll
Database1 -> C:\git\Store\Database1\bin\Debug\Database1.dacpac
------ Deploy started: Project: Database1, Configuration: Debug Any CPU ------
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72023: The database containment option has been changed to None. This may result in deployment failure if the state of the database is not compliant with this containment level.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Organization].[BillingId] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Person].[CompanyName] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Person].[IsBilling] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Person].[IsEnabled] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[BillingErrorDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[BillingMode] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[BillingStatus] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[ChargeToken] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[DeactivateDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[DeleteDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[Discount] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[NextBaseBillingDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[NextOverageBillingDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Warning: SQL72015: The column [dbo].[Subscription].[ShutoffDate] is being dropped, data loss could occur.
C:\git\Store\Database1\bin\Debug\Database1.sql: Error: SQL72031: This deployment may encounter errors during execution because changes to [dbo].[Subscription].[ApiKey1] are blocked by [dbo].[Subscription].[IX_Subscription_ApiKey]'s dependency in the target database.
C:\git\Store\Database1\bin\Debug\Database1.sql: Error: Deploy72002: Plan verification encountered errors; deployment cannot continue.
Done building project "Database1.sqlproj" -- FAILED.
Build FAILED.
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
不再有 IX_Subscription_ApiKey(它被替换为 IX_Subscription_ApiKey1)。
subscription.sql 文件是(“123”和“4546”只是为了尝试让它运行):
CREATE TABLE [dbo].[Subscription] (
[SubscriptionId] BIGINT IDENTITY (1, 1) NOT NULL,
[OrganizationId] BIGINT NOT NULL,
[SubscriptionName] NVARCHAR (255) NOT NULL,
[ApiKey1] CHAR (36) NOT NULL DEFAULT '123' ,
[ApiKey2] CHAR (36) NOT NULL DEFAULT '4546' ,
[IsEnabled] BIT CONSTRAINT [DF_Subscription_Enabled] DEFAULT ((1)) NOT NULL,
[IsActive] BIT CONSTRAINT [DF_Subscription_Active] DEFAULT ((1)) NOT NULL,
[AccruedRtusThisMonth] BIGINT CONSTRAINT [DF_Subscription_PendingRtus] DEFAULT ((0)) NOT NULL,
[BilledRtusThisMonth] BIGINT CONSTRAINT [DF_Subscription_PaidRtus] DEFAULT ((0)) NOT NULL,
[OverageChargesThisMonth] MONEY CONSTRAINT [DF_Subscription_OverageChargesThisMonth] DEFAULT ((0)) NOT NULL,
[PricingMode] TINYINT NOT NULL,
[PricingPlanId] BIGINT NULL,
[MaxAdditionalMonthlyCharge] MONEY NOT NULL,
[XtraAutoTags] INT CONSTRAINT [DF_Subscription_XtraAutoTags_1] DEFAULT ((0)) NOT NULL,
[EndFreeUse] SMALLDATETIME CONSTRAINT [DF_Subscription_EndFreeUse_1] DEFAULT (getutcdate()) NOT NULL,
[Created] SMALLDATETIME CONSTRAINT [DF_Subscription_CreatedDate] DEFAULT (getutcdate()) NOT NULL,
[TS] ROWVERSION NOT NULL,
CONSTRAINT [PK_Subscription] PRIMARY KEY CLUSTERED ([SubscriptionId] ASC),
CONSTRAINT [FK_Subscription_PricingPlan] FOREIGN KEY ([PricingPlanId]) REFERENCES [dbo].[PricingPlan] ([PricingPlanId]),
CONSTRAINT [FK_Subscription_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([OrganizationId])
);
GO
CREATE NONCLUSTERED INDEX [IX_Subscription_OrganizationId]
ON [dbo].[Subscription] ([OrganizationId] ASC);
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Subscription_ApiKey1]
ON [dbo].[Subscription]([ApiKey1] ASC);
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Subscription_ApiKey2]
ON [dbo].[Subscription]([ApiKey2] ASC);
GO
CREATE NONCLUSTERED INDEX [IX_Subscription_EndFreeUse]
ON [dbo].[Subscription]([EndFreeUse] ASC);
GO
CREATE UNIQUE NONCLUSTERED INDEX [IX_Subscription_Name]
ON [dbo].[Subscription]([SubscriptionName] ASC);
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'The primary key',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'SubscriptionId'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'FK to the Organization that owns this credit card',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'OrganizationId'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'The key supplied to the engine & AutoTag',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'ApiKey1'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'Alternative key. Either can be used.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'ApiKey2'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'The customer sets to false to turn this off.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'IsEnabled'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'Windward sets to false to force this off.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'IsActive'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'RTUs that have accrued so far this month.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'AccruedRtusThisMonth'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'RTUs that have been paid for so far this month. Includes the RTUs that come with the monthly plan.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'BilledRtusThisMonth'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'How much has accrued in overages so far this month.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'OverageChargesThisMonth'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'The maximum allowed to charge for overages each month. Reports are disallowed after hitting this maximum.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'MaxAdditionalMonthlyCharge'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'Number of additional AutoTags purchased.',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'XtraAutoTags'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'Date that free use (trial) ends',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'EndFreeUse'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'Date this record was created',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'Created'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'The pricing plan on. 1 = bronze, 2 = silver, 3 = gold, 4 = platinum, 255 = custom',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'PricingMode'
GO
EXEC sp_addextendedproperty @name = N'MS_Description',
@value = N'FK to the pricing plan if a custom plan',
@level0type = N'SCHEMA',
@level0name = N'dbo',
@level1type = N'TABLE',
@level1name = N'Subscription',
@level2type = N'COLUMN',
@level2name = N'PricingPlanId'
为什么不开心?
谢谢 - 戴夫
解决方案
我想通了。打开 SSMS 并连接到 (LocalDb)\ProjectsV13(将 ProjectsV13 替换为您的数据库名称)。在我的情况下,数据库位于 C:\Users\david\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\ProjectsV13 中,名称来自文件夹。
打开后,在 SSMS 中选择数据库并将其删除。一旦你知道该怎么做,真正简单的解决方案。
顺便说一句 - 连接到 localhost 不会为您提供本地数据库。只是 (localdb) 不起作用。
推荐阅读
- wordpress - 当备份来自 Web 存档(html、js、css 文件)时,如何恢复 Wordpress 站点?
- python - 拆分熊猫文本数据框的行
- java - 当我们在 test 文件夹中定义一个 bean 时会发生什么?
- css - Live Sass 编译器仍在抱怨我已经修复的错误
- flutter - StaggeredGridView.countBuilder 正在渲染所有内容,而不仅仅是用户可见的部分,导致严重的性能问题
- ios - 更新数组对象并在collectionView中显示
- python-3.x - 相交两个字典并获得平均分数
- javascript - 使用 Fetch 提交表单并接收响应以使用它
- python-requests - 将正文解析为 json 时失败 - 使用 request.post() 调用 Rasa API
- java - openfein + spring data 自动嵌套实体检索