1

I'm struggling a bit to overcome this obstacle that is to create a table with a foreign key to another table. It looks simple right? It is, but unfortunately i'm not being successfull. The error thrown is the one in the title. Has anyone else had this error before? How did you resolved it? I'm using SQL Server 2014 but the error is thrown through Outsystems IDE.

Best regards, Rafael Valente

Rafael Valente
  • 763
  • 1
  • 6
  • 13
  • I forgot to mention that i don't understand how this error is thrown since i'm creating the table and therefore, there are no records in it. – Rafael Valente Feb 01 '17 at 16:20
  • So there are no records in either table? Maybe you have the foreign keys back to front – Snowlockk Feb 01 '17 at 16:22
  • There are records in one of the tables. The other one, that i'm creating, doesn't have any records and it is in this one that i'm trying to create a foreign key to the other that already exists. But when i try to do it the error in the title is thrown. Do you have any idea why? – Rafael Valente Feb 01 '17 at 16:27
  • Please add the information about this being a new table to the question. – Dan Bracuk Feb 01 '17 at 16:29
  • P_Id int FOREIGN KEY REFERENCES Persons(P_Id) Are you sure you don't have the table being referenced as the new one? Only thing I can think of off the top of my head, – Snowlockk Feb 01 '17 at 16:30
  • @DanBracuk is the question fine now? – Rafael Valente Feb 01 '17 at 16:34
  • @Snowlockk the table is being created from the Outsystems Platform. Almost everything is automatic. Apart from this, there are 2 other FK's in my new table and the constraints related to these 2 other FK's are built successfully. – Rafael Valente Feb 01 '17 at 16:35

1 Answers1

1

It would help if you could post a picture of your datamodel for us to take a look.

One way of dealing with this kind of errors in OutSystems is inspecting the database itself. There's a system table called ossys_espace. Get your espace id from there. Then query ossys_entity to see which is the physical table name for that entity and check if there's something wrong with it.

There's also the possibility that you've created a table in the past that is causing the error. Check for the entities with the flag deleted set to true in that table. If it helps, there's this Forge component that you can you to clean those deleted entities.

If you have access to the server you can also look at the generated SQL and understand if there's a problem with it.

I find that error weird, but you might be bumping into a bug, and for sure we want to know that :)

Pedro Cardoso
  • 373
  • 3
  • 7
  • My new table already had some foreign keys so to overcome this, i created the new column (that will be the new FK) with the same data type of the PK that i'm refering in the other table. Published it, then ran in SQL Sserver the same script that was stored in DB for the other FK of my new table. Just changed the columns that i wanted and published it again. And success!! – Rafael Valente Feb 09 '17 at 08:23