0

尝试从 db 解决方案构建项目时遇到奇怪的错误。

例如。我有一张桌子

CREATE TABLE [dbo].[partner2_log_status] (
    [rec_id]     INT             IDENTITY (1, 1) NOT NULL,
    [log_status] INT             NULL,
    [log_msg]    NVARCHAR (4000) NULL,
    [log_count]  BIGINT          CONSTRAINT [DF_partner2_log_status_log_count] DEFAULT ((0)) NOT NULL,
    [sys_dt]     DATETIME        CONSTRAINT [DF_partner2_log_status_sys_dt] DEFAULT (getdate()) NOT NULL,
    CONSTRAINT [PK_partner2_log_status] PRIMARY KEY CLUSTERED ([rec_id] ASC)
);

这就是我得到的:

SQL71508:模型已经有一个同名的元素 dbo.partner2_log_status。
SQL71501:默认约束:[dbo].[DF_partner2_log_status_log_count] 对列 [dbo].[partner2_log_status].[log_count] 的引用未解析。

但是项目中只有一个同名的表。

等等等等...
10 个项目中出现约 1,7k 错误。

当我在 Visual Studio 中查看/构建时,整个解决方案都会发生这种情况。SSMS 接受代码,并成功执行,所以这似乎是 VS 独有的问题。

发生了什么,我该如何解决?

4

2 回答 2

0

I know this is an old question, but I've been looking and looking for a while. I had 1 database project in my solution that I had tried to add a folder to with a few scripts. Suddenly, the project wouldn't build (even though I set those scripts to not build). I was getting the SQL errors mentioned in the original question for every object in the database. Every table, field, constraint, view, etc. was reporting as already in the model. I deleted the folder and scripts I had added, but it still didn't build. Restarted VS, reset my git branch, and whatever else I could think of. Still the same errors.

I finally came across this post: SQL Database Project: build different scripts depending on build configuration

It mentions the dbmdl cache file. I went and deleted that file in my project directory and the next build worked like a charm. Maybe that will help someone else getting this error when there aren't actually duplicate objects defined.

于 2017-10-27T04:32:01.797 回答
0

关于第一个错误,

SQL71508:模型已经有一个同名的元素 dbo.partner2_log_status

表示“dbo.partner2_log_status”在您的项目中至少再次使用过一次。

为了解决这个错误,需要检查所有使用同名变量的表,并将其删除。它可能在另一个约束内。

于 2016-03-06T14:32:22.907 回答