How do I create a database table in the setup file for a Drupal module?

I am creating a module for Drupal 7.x and I want to create a database table when the module is installed (enabled for the first time). How can i do this? Thanks.

+2


a source to share


2 answers


You need to implement in your unit install_schema

and uninstall_schema

hooks that return information about the circuit. They are converted to a create and drop table and executed by Drupal when your module is enabled or removed. Read more in the schema API .



-3


a source


Old post, I know, but for the sake of completeness:

hook_install_schema and hook_uninstall_schema are no longer needed since drupal 7.x



http://api.drupal.org/api/drupal/includes--database--schema.inc/group/schemaapi

You can just get rid of the hook_schema () implementation.

+7


a source







All Articles