databasepostgresqldelphiforeign-keysdata-transfer

How to copy data to identical Postgres table with foreign key using Delphi?


I am trying to copy data from table Orders to table Order_History. Both tables have a foreign key to Details and Detail_History.

We have an Ordernumber column in both orders tables and a corresponding Link_Ordernumber column in both details tables.

I tried this code:

tblorderhist.Insert;
tblorderhist.CopyFields(DataModule1.tblorders);
tblorderhist.Post;
tbldetailHist.Insert;
tbldetailHist.CopyFields(DataModule1.tblline);
tbldetailHist.Post;

and on the line

tblorderhist.CopyFields(DataModule1.tblorders);

Delphi throws the error

Project Prjdoors.exe raised exception class EDatabaseError with message 'Field 'orderno' cannot be modified'.


Solution

  • Your error

    Project Prjdoors.exe raised exception class EDatabaseError with message 'Field 'orderno' cannot be modified'.

    suggestions that you can't modify your TField.

    Disable the property ReadOnly of your ordernumber/orderno (not clear enough, error says something else as your question) TField.