You are not logged in.
I have a module that contains several classes mapped to database tables. When I use CreateMissingTables in mORMot, it creates the missing tables for the classes. However, there is an issue:
CreateMissingTables automatically adds an ID field to the tables it creates.
In my case, some classes already have an ID field defined as varchar, but CreateMissingTables still tries to add its default ID field as integer.
This causes a conflict because the table ends up with the wrong type for the ID field, or sometimes it fails to create the table correctly.
Goal:
I want CreateMissingTables to respect the existing ID fields in my classes and not automatically add an integer ID field, especially when my class already defines a varchar ID.
Offline
As documented, and as required by SQLite3 virtual tables process, the ORM requires an integer primary key for external tables, even if you don't use SQLite3.
Even the IRestOrm itself makes use of this "RowID" integer primary key.
So what you can do is map this "RowID" field to an existing integer field, to be used as primary key, perhaps in addition to the existing varchar ID. The ORM can populate the RowID field for you.
Offline
Thank you for the explanation.
I understand that the ORM requires an integer RowID primary key even for external tables.
However, could you please provide a small example showing how to define a class that uses a varchar ID field together with this RowID integer key?
For example:
How should I declare the class in Delphi?
How to map the RowID to an existing integer field in my external MySQL table?
A short code snippet or schema example would help me understand it better.
Offline
Please try
MyModel.Props[TMyTable].ExternalDB.MapField('ID', 'MY_TABLE_ID');
Offline