删除索引使用VS 2017数据库项目创建数据库时出错

问题描述 投票:-2回答:1

我有一个我在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'

为什么不开心?

谢谢 - 戴夫

sql-server visual-studio
1个回答
0
投票

我想通了。打开SSMS并连接到(LocalDb)\ ProjectsV13(将ProjectsV13替换为您的数据库的名称)。在我的情况下,数据库位于C:\ Users \ david \ AppData \ Local \ Microsoft \ Microsoft SQL Server Local DB \ Instances \ ProjectsV13,名称来自该文件夹。

打开后,选择SSMS中的DB并将其删除。一旦你知道该怎么做,真的很简单。

BTW - 连接到localhost不会提供本地数据库。只是(localdb)不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.