0

I am experiencing weird errors when trying to build the project from db solution.

EG. I have a table

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)
);

and this is what I'm getting :

SQL71508: The model already has an element that has the same name dbo.partner2_log_status.
SQL71501: Default Constraint: [dbo].[DF_partner2_log_status_log_count] has an unresolved reference to Column [dbo].[partner2_log_status].[log_count].

But there is only one table with this name in the project.

etc etc...
~1,7k errors in 10 projects.

This is happening across whole solution when I view/build in Visual Studio. SSMS accepts the code, and executes it successfully , so it seems to be a problem solely with VS.

What is happening, and how do I resolve it ?

evictednoise
  • 587
  • 1
  • 7
  • 19

2 Answers2

0

About the first error,

SQL71508: The model already has an element that has the same name dbo.partner2_log_status

means that "dbo.partner2_log_status" was used at least once more in your project.

In order to solve this error, one will need to check all tables where the variable with the same name was used, and remove it. It could be inside another Constraint.

Soreges
  • 16
  • 3
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.

user2517183
  • 126
  • 5