0
    function recipe_submit_schema() {
  $schema['recipe_submit'] = array(
    'description' => 'Recipe base table.',
    'fields' => array(
      'recipe_id' => array(
        'description' => 'Primary identifier for recipe.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not_null' => TRUE,
      ),
      'recipe_title' => array(
        'description' => 'Recipe Title.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
      ),
      'author_name' => array(
        'description' => 'The author of the recipe.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
      ),
      'author_email' => array(
        'description' => 'The author email.',
        'type' => 'varchar',
        'length' => 255,
        'default' => '',
      ),
      'recipe_description' => array(
        'description' => 'Recipe description.',
        'type' => 'text',
      ),
      'recipe_instructions' => array(
        'description' => 'Recipe instructions.',
        'type' => 'text',
      ),
      'recipe_ingredients' => array(
        'description' => 'Recipe ingredients.',
        'type' => 'text',
      ),
    ),
    'primary key' => array('recipe_id'),
  );

  return $schema;
}

gives me following error

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1171 All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key, use UNIQUE instead in /home/insasse/test_workspace/drupal7/includes/database/database.inc:2227                                                     [error]
Stack trace:
#0 /home/insasse/test_workspace/drupal7/includes/database/database.inc(2227): PDOStatement->execute(Array)
#1 /home/insasse/test_workspace/drupal7/includes/database/database.inc(697): DatabaseStatementBase->execute(Array, Array)
#2 /home/insasse/test_workspace/drupal7/includes/database/schema.inc(664): DatabaseConnection->query('CREATE TABLE {r...')
#3 /home/insasse/test_workspace/drupal7/includes/database/database.inc(2776): DatabaseSchema->createTable('recipe_submit', Array)
#4 /home/insasse/test_workspace/drupal7/includes/common.inc(7114): db_create_table('recipe_submit', Array)
#5 /home/insasse/test_workspace/drupal7/includes/module.inc(479): drupal_install_schema('recipe_submit')
#6 /home/insasse/.composer/vendor/drush/drush/commands/core/drupal/environment_7.inc(143): module_enable(Array)
#7 /home/insasse/.composer/vendor/drush/drush/commands/pm/pm.drush.inc(1167): drush_module_enable(Array)
#8 /home/insasse/.composer/vendor/drush/drush/includes/command.inc(422): drush_pm_enable('recipe_submit')
#9 /home/insasse/.composer/vendor/drush/drush/includes/command.inc(231): _drush_invoke_hooks(Array, Array)
#10 /home/insasse/.composer/vendor/drush/drush/includes/command.inc(199): drush_command('recipe_submit')
#11 /home/insasse/.composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php(67): drush_dispatch(Array)
#12 /home/insasse/.composer/vendor/drush/drush/includes/preflight.inc(66): Drush\Boot\BaseBoot->bootstrap_and_dispatch()
#13 /home/insasse/.composer/vendor/drush/drush/drush.php(12): drush_main()
#14 {main}

What am I doing wrong?

2 Answers 2

1

Try replacing 'primary_key' with 'primary key'

2
  • Do you still get the same error, even when you use primary key? I also think that should fix your error. Feb 13, 2017 at 9:07
  • 1
    Try using 'not null' instead of 'not_null' in the recipe_id field definition
    – OPTASY
    Feb 13, 2017 at 9:11
1

Change from 'not_null' => TRUE, to 'not null' => TRUE.

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