1

I'm writing a module that will enable an editor to determine whether a script is available on a specific node, in order to improve page load times.

I need to create a database table to hold an indicator showing, for each node ID, whether the script is available. My code is this.

function script_show_schema() { 
    $schema['script_show_enabled'] = array(
        'description' => 'Tracks whether Script Show is enabled for a given node',
        'fields' => array(
            'nid' => array(
                'description' => 'The {node}.nid that has Script Show enabled', 
                'type' => 'int', 
}               'not null' => TRUE, 
                'default' => 0, 
            ),
        ),
        'primary key' => array('nid'),
    ); 
    return $schema;
}

I've disabled, then uninstalled, then re-enabled my module through the admin UI, (as opposed to using Drush), but I still don't seem to be able to see my database tables.

I know this question has been asked a couple of times before, but usually the solution seems to be the uninstall thing.

Does anyone have any idea on what is going wrong? I wonder if it's a DB permissions thing. But then, I guess Drupal has root access to the DB in order to create its tables in the first place.

Updates:

I am using version 7.23 of the core.

Here's my .info file:

; $Id$ 
name = Script Show
description = "Allows the user to specify that the Maxymiser script will only execute on specific pages"
package = JD Dev Modules
core = 7.x
files[] = script_show.module


flag

My entire module is here: github.com/jamesdesq/script_show.

12
  • In which file is located this hook? – xurshid29 Apr 2 '14 at 10:41
  • @xurshid29 it's in script_show.install, which is in the root of the module file (so sites/all/modules/custom/script_show) – jamesdesq Apr 2 '14 at 11:08
  • try to add another serial type field (just for experiment) and change nid primary key to that field.. – xurshid29 Apr 2 '14 at 11:19
  • I can't say that it's a drupal issue.. I think you should include some information to the question: what version of drupal you are using, structure of module files, what .info file contains, .module file exists or not and so on.. Because, I tried you code and I can see it's creating script_show_enabled table.. – xurshid29 Apr 2 '14 at 11:49
  • you can see that created table here – xurshid29 Apr 2 '14 at 11:58
0

The code in your git repo is not the same as the code posted here. Both has syntax errors. See @ARUN's answer for the bug in the code posted here.

As for the code in the git repo, there are two lines of random junk in it (indicated with red striketroughs below), causing Drupal to crash before the table is created in the database.

enter image description here

Remove those two lines and try again.

0

I tried your code. There is one syntax error at line no:8 (one additional }). Remove that and try. It is working.

function script_show_schema() { 
  $schema['script_show_enabled'] = array(
    'description' => 'Tracks whether Script Show is enabled for a given node',
    'fields' => array(
        'nid' => array(
            'description' => 'The {node}.nid that has Script Show enabled', 
            'type' => 'int', 
           'not null' => TRUE, 
            'default' => 0, 
        ),
    ),
    'primary key' => array('nid'),
  ); 
return $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.