user142019
user142019

Reputation:

How to create a database table in an installation 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.

Upvotes: 2

Views: 7303

Answers (2)

Andrew
Andrew

Reputation: 946

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

hook_install_schema and hook_uninstall_schema are no longer necessary as of drupal 7.x

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

You can get away with just implementing hook_schema().

Upvotes: 7

spoulson
spoulson

Reputation: 21591

You need to implement install_schema and uninstall_schema hooks in your module that return schema information. These are translated into table create and drop and executed by Drupal when your module is enabled or uninstalled. Read more in the Schema API.

Upvotes: -3

Related Questions