cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
TiagoFreire
Level 8

Form cannot save to Azure SQL Table with FOREIGN KEY SAME TABLE constraint

Hi all, 

 

I have a table where I want to structure a parent-child relationship. 

 

The way I intend to do thisis by means of other columns in the same table referencing the primary key by means of a foreign key. 

 

the 3 columsn in question are: 

 

id - primary key, identity autoincrement

root_id - foreign key to id

parent_id - foreign key to id

 

I would use the root_id to fetch all child items of a root node, or the parent_id to fetch the immediate siblings.

 

foreign key columns are set to accept NULL values. 

 

When I try to save it though, I get the error: 

 

Invalid Solicitation.

Server Response: Microsoft SQL: The INSERT statement conflicted with the FOREIGN KEY SAME TABLE constraint "FK_process_item_process_item2".

 

Are FOREIGN KEY SAME TABLE simply unsupported, or there is some trick to saving to it? 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Form cannot save to Azure SQL Table with FOREIGN KEY SAME TABLE constraint

Hi @TiagoFreire ,

Do you define Foreign keys within your SQL table?

 

Currently, within PowerApps,  the FOREIGN KEY SAME TABLE constraint is not supported. If you want to insert records into a SQL Table which has defined FOREIGN KEY SAME TABLE within, the conflict error would show up.

 

Actually, it is not necessary to define FOREIGN KEY SAME TABLE constraint within your SQL Table. Based on the needs that you mentioned, I think the Filter function in PowerApps could achieve your needs.

If you want to fetch all child items of a root node, please take a try with the following formula:

Filter(
         '[dbo].[YourSQLTable]',
         root_id = "A specific id value"
)

If you want to fetch the immediate siblings, please take a try with the following formula:

Filter(
         '[dbo].[YourSQLTable]',
         parent_id = "A specific id value"
)

Please consider take a try to remove the FOREIGN KEY SAME TABLE constraints from your SQL Table, then re-create a new app based on your SQL table, take a try with above Filter formulas to retrieve proper records.

 

More details about Filter function, please check the following article:

Filter function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
1 REPLY 1
Community Support Team
Community Support Team

Re: Form cannot save to Azure SQL Table with FOREIGN KEY SAME TABLE constraint

Hi @TiagoFreire ,

Do you define Foreign keys within your SQL table?

 

Currently, within PowerApps,  the FOREIGN KEY SAME TABLE constraint is not supported. If you want to insert records into a SQL Table which has defined FOREIGN KEY SAME TABLE within, the conflict error would show up.

 

Actually, it is not necessary to define FOREIGN KEY SAME TABLE constraint within your SQL Table. Based on the needs that you mentioned, I think the Filter function in PowerApps could achieve your needs.

If you want to fetch all child items of a root node, please take a try with the following formula:

Filter(
         '[dbo].[YourSQLTable]',
         root_id = "A specific id value"
)

If you want to fetch the immediate siblings, please take a try with the following formula:

Filter(
         '[dbo].[YourSQLTable]',
         parent_id = "A specific id value"
)

Please consider take a try to remove the FOREIGN KEY SAME TABLE constraints from your SQL Table, then re-create a new app based on your SQL table, take a try with above Filter formulas to retrieve proper records.

 

More details about Filter function, please check the following article:

Filter function

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
firstImage

PowerApps Monthly Community Call!

Join us next Wednesday for our Demo Extravaganza, October 16, 2019 8am PDT.

firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 177 members 5,399 guests
Please welcome our newest community members: