This project is read-only.

Why is it impossible to create a foreign key using a column in a setting table ?

Topics: Customizing Orchard, Troubleshooting, Writing modules
Nov 7, 2013 at 11:58 AM
Edited Nov 7, 2013 at 12:03 PM
My module has its own system settings and I want to select in these settings a default content (customer in this case).
I proceeded as I usually did in normal parts

SchemaBuilder.CreateForeignKey("FK_AdminUserConnectorsSettings_Customer", "ConnectorsSettingsPartRecord", new[] { "AdminUser_Id" }, "Datwendo.Commerce", "CustomerPartRecord", new[] { "Id" });

but there is an exception in the foreign key creation
Orchard.Data.Migration.DataMigrationManager - Error while running migration version 16 for Datwendo.Connectors
System.Reflection.TargetInvocationException: ---> System.Data.SqlServerCe.SqlCeException: A foreign key value cannot be inserted because a corresponding primary key value does not exist. [ Foreign key constraint name = FK_AdminUserConnectorsSettings_Customer ]

If I apply exactly the same code in a normal part I don't get the exception ???
Is NH is doing something different for settings parts ?

Edit: The error message in the exception is strange, I have already Foreign keys on <CustomerPart, Id> and usually we don't need an index for the source column?