سؤال

<?php

function kronos_schema() {
  $schema=array();
  $schema['kronos'] = array(

      'description' => 'An example table.',
     'fields' => array(
      'fe_id' => array(
        'description' => 'The primary identifier for a node.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'Date' => array(
        'description' => 'A field for storing date',
        'type' => 'datetime',
        'not null' => TRUE,
      ),
      'mytextfield' => array(
        'description' => 'A field for storing short strings of text.',
        'type' => 'varchar',
        'length' => 50,
        'not null' => TRUE,
        'default' => '',
      ),
      'mytext' => array(
        'description' => 'A field for storing longer text',
        'type' => 'text',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array('fe_id'),
  );
  return $schema;
}

this code gives me the following error : Notice: Undefined index: datetime:normal in DatabaseSchema_mysql->processField() (line 205 of C:\Documents and Settings\djeewani-si\Sites\acquia-drupal\includes\database\mysql\schema.inc). PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT NULL COMMENT 'A field for storing an integer number', mytextfield VARCHAR' at line 3: CREATE TABLE {kronos} ( fe_id INT unsigned NOT NULL auto_increment COMMENT 'The primary identifier for a node.', Date NOT NULL COMMENT 'A field for storing an integer number', mytextfield VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'A field for storing short strings of text.', mytext TEXT NOT NULL COMMENT 'A field for storing longer text', PRIMARY KEY (fe_id) ) ENGINE = InnoDB DEFAULT CHARACTER SET utf8 COMMENT 'An example table.'; Array ( ) in db_create_table() (line 2717 of C:\Documents and Settings\djeewani-si\Sites\acquia-drupal\includes\database\database.inc).

هل كانت مفيدة؟

المحلول

Datetime support was removed from D7 db api - use mysql_type or pgsql_type if you want this functionality.

Try this :

'Date' => array(
  'description' => 'A field for storing date',
  'type' => 'datetime',
  'mysql_type' => 'datetime',
  'not null' => TRUE,
)

Reference: https://drupal.org/node/159605

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top