Error SQL01268: Cannot insert duplicate key in object 'dbo.ComponentTypeRef'
Error SQL01268: .Net SqlClient Data Provider: Msg 2627, Level 14, State 1, Line 3 Violation of PRIMARY KEY constraint 'PK_ComponentTypeLu'. Cannot insert duplicate key in object 'dbo.ComponentTypeRef'.
An error occurred while the batch was being executed
Working with Database Projects in Visual Studio 2010 can be very interesting, until it start throwing many weird errors. Actually once you get comfortable using it, you will enjoy the experience. Its work exploring.
You can create your schemas, stored procedures and other database objects and just deploy them to a database you want to target to. When you attempt to deploy your database project to a database you might get an error similar to the one above.
I got the above error and here is how I resolved it. I figured out that I was getting the above errors because I had some existing records in some of the tables in the database I was targeting, so it was trying to insert duplicate records. To resolve it, I deleted my existing database (delete the database only if its fine with you, better to take a back up of the database before you delete, or if you can find the existing records that are causing the duplicate errors and delete those records) and then deployed my database project, it created my new database and everything worked fine.
Hope that’s helpful!