I'm coming from a do-it-yourself database design background, so bare with me. Let's say I want two database tables, one of car manufacturers, and one of car models. The first table, car_make, would have two fields, a primary key (car_make_id) and a string (car_make_name). The second table, car_model, would have a primary key (car_model_id) a foreign key referencing car_make (car_model_id), a string (car_model_name), and, let's say, a numeric for engine size (car_make_liters).

I just installed the drupal console to generate the boilerplate code. It looks like an Entity might be the best candidate. I can use the admin/structure space to add fields to the Entities and link them together. However, If I uninstall the module, this fields are removed. How do I create this field structure (schema?) within the module? If fields are not the best way to do this, let me know.

  • 1
    I think this is a bit opinionated as to whether to use a custom content entity, core/contrib content entity (taxonomy, node), or a completely custom table (if foreign key is required). One thing to note is that "Fields" can refer to "Bundle Fields" or "Base Fields" which behave a bit differently storage-wise. – mradcliffe Apr 12 '16 at 17:25
  • It looks like foreign keys are not supported by Drupal, but referential integrity is maintained within the application if using fields and entities. – Kevin Nowaczyk Apr 13 '16 at 14:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.