I am having trouble adding foreign key constraint to my table. I have two schemas in my db 'XYZ' and 'ABC' and I want to reference a table from one schema to another. The query I have mentioned below is working fine on SQL server however when building the solution on VS2015 I am getting SQL71501 error.
CREATE TABLE [XYZ].[ProductData]
(
[ID] [int] IDENTITY(100,1) NOT NULL,
[ExchangePlanID] [varchar](25) NULL,
[OracleFinanceMarketNbr] [int] NULL,
[IssueStateCode] [char](2) NULL,
[PlanID] [varchar](50) NULL,
[PrimaryPlatformCode] [char](4) NULL,
[PlanYear] smallint NOT NULL,
[VersionRefID] int NOT NULL,
[InsertedBy] [varchar](50) NOT NULL DEFAULT (suser_sname()),
[InsertedOnUTC] [datetime] NOT NULL DEFAULT (getutcdate()),
[ModifiedBy] [varchar](50) NOT NULL DEFAULT (suser_sname()),
[ModifiedOnUTC] [datetime] NOT NULL DEFAULT (getutcdate()),
PRIMARY KEY CLUSTERED
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 90) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [XYZ].[ProductData] WITH CHECK ADD CONSTRAINT [FK_ProductData_VersionRefID]
FOREIGN KEY([VersionRefId]) REFERENCES [ABC].[VersionInfo] ([ID])
GO
Table [ABC].[VersionInfo] is alread present in the DB.
If am referncing a table from same schema i.e. 'XYZ' then I am not gettting any error while building my solution.
Could anyone point me in the right direction ?