1

While developing a custom module in Drupal 7, which function actually creates tables in the database?

I have implemented hook_schema in mymodule.install, mymodule.info, mymodule.module file and defined the Controller class and creates an StdClass object, but still I can't seem to find my tables in my database.

Can anybody tell me what I could be doing wrong?

2
  • did u enable module? can u paste your code?
    – monymirza
    Mar 26, 2013 at 7:08
  • 1
    hook_schema should write only in .install file.
    – monymirza
    Mar 26, 2013 at 7:10

1 Answer 1

3

First things first, you are using the correct hook.

If your module is already enabled, then the implementation of hook_schema() won't get called. This is also the case if the module has been enabled, and then disabled without uninstalling.

I would try disabling your module, and then ensuring it is uninstalled by either heading to admin/modules/uninstall/ or (if you have Drush installed) run drush pm-uninstall mymodule

From the documentation:

The tables declared by this hook will be automatically created when the module is first enabled, and removed when the module is uninstalled. This happens before hook_install() is invoked, and after hook_uninstall() is invoked, respectively.

I'm not sure why you'd be defining a controller class though, or even which one you're defining. Drupal 7 does this with an array, it's not very OO (Drupal 6/7 is array soup).

If this doesn't solve your issue perhaps you could paste a munged version of your implementation of hook_schema.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.